I have Debian stretch with systemd running (installed by default). I want to start a 2 lines bash script at boot via cron.   echo something &gt; file.txt   xfce4-terminal  [...] --command="watch [....]" 2&gt;&amp;1 &amp;    the script works fine when launched manually: A window is opened and  a 'watch' command is launched.  I use use the first line to check if it's launched at boot (like a kind of stamp).  I have tried with root user and non root.  I edited cron with crontab -e and vi (export VISUAL="vi")  @reboot /path/to/script/script.sh   At boot, the script is launched (I checked file.txt), but the window opened by xfce4-terminal is not there. And... 'Systemd' looks like big Berta for just launching a script at boot....  Any idea? thank you folks!
1867
Once upon a time,  DISPLAY=:0.0 totem /path/to/movie.avi   after ssh 'ing into my desktop from my laptop would cause totem to play movie.avi on my desktop.  Now it gives the error:   No protocol specified Cannot open display:    I reinstalled Debian squeeze when it went stable on both computers, and I guess I broke the config.   I've googled on this, and cannot for the life of me figure out what I'm supposed to be doing.   (VLC has an HTTP interface that works, but it isn't as convenient as ssh.)  The same problem arises when I try to run this from a cron job.
36995
After doing a "sudo su -" on an Ubuntu 12.04 notebook I did a "crontab -e", added this:   * * * * * env DISPLAY=:0.0 /usr/bin/gnome-calculator   and waited for minutes. Nothing Happened. I don't have any external monitors and if I run this command "env DISPLAY=:0.0 /usr/bin/gnome-calculator" in the terminal, it just works. But not from cron. Why?   The syslog only contains this:   May 24 14:37:01 localhost cron[1227]: (root) RELOAD (crontabs/root) May 24 14:37:01 localhost CRON[16432]: (root) CMD (env DISPLAY=:0.0 /usr/bin/gnome-calculator )   And I already tried an "xhost +localhost".   [root@NOTEBOOK /var/log] xhost access control enabled, only authorized clients can connect INET:localhost.localdomain SI:localuser:USERNAME [root@NOTEBOOK /var/log]    So the solution for another question like this on askubunut didn't worked.
92130
I have created a script to install two scripts on to the crontab.   #!/bin/bash   sudo crontab -l &gt; mycron  #echo new cron into cron file   echo "*/05 * * * * bash /mnt/md0/capture/delete_old_pcap.sh" &gt;&gt; mycron #schedule the delete script  echo "*/12 * * * * bash  /mnt/md0/capture/merge_pcap.sh" &gt;&gt; mycron     #schedule the merge script  #install new cron file  crontab mycron rm mycron   The script runs, and add the two lines to the crontab. But if I run the script again, it adds those lines again , thus I will have four lines saying the same stuff. I want the install script to run such that, the lines inserted to the crontab do not repeat. How can I do that
9996
I have raspbian running on my raspberry PI. When I switch it on, boot messages crawl on the screen. I believe it would be beneficial to read them in order to get an idea about how the system starts. Hence I would like to know whether it is possible (and how) to redirect them to a file in order to read them thoroughly afterwards. Do I have to make a script that runs at startup?
36970
I have some applications that need to run on my laptop all the time.   I use a bash script to start these applications. In my script I have a loop that looks similar to this:    while true; do     xterm done   This runs an application (xterm in this case) and if the application crashes, the loop starts it again.    This has a disadvantage that there is no "clean" exit from this loop. So even if the intention of the user is to close xterm, the loop starts it again.    Is there a way to start an application from bash script, watch whether it is running, to re-run it if script crashed or do nothing if the user closed it properly ?
86211
I would like to start Debian without the GUI and then just type commands in to launch the desired programs (which are located on my local machine), eg  $ chromium-browser &amp;   I already do a similar thing when sshing in to other machines on the LAN - it is handy if I need to visualise csv data for example in soffice. i currently have gnome desktop and Debian 7 installed.  I have , however I am reluctant to try them out for fear of being locked out of using the web browser once I do this (I will need it to seek help using the browser if I get stuck).  I was wondering if I could temporarily test out the method of starting the GUI on one of the other terminals (eg ctrl+alt+f1) to see if there are any problems? Will this work? Will it be equivalent to starting the GUI when booting without a GUI?  If this is feasible, please could someone provide full instructions for:   enabling the GUI on terminal f1 so that i can run gui programs (without showing the full desktop interface) turning off the desktop interface GUI on bootup   obviously I will need to run X11 to load GUI programs - that's fine, but I'm looking to boot up into text mode and then just execute GUI programs as needed.  doing some tests on an ubuntu 12.04 virtualbox vm (hopefully not too different to debian 7?)...  $ ps aux | grep gdm # *blank* $ ps aux | grep kdm # *blank* $ ps aux | grep lightdm root      1225  0.0  0.0 270664  3500 ?        Ssl  12:43   0:00 lightdm root      1234  1.9  2.2 236564 112276 tty7    Ss+  12:43   0:01 /usr/bin/X :0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch -background none root      1382  0.0  0.0 156772  3572 ?        Sl   12:43   0:00 lightdm --session-child 12 19 $ sudo update-rc.d lightdm disable update-rc.d: warning: /etc/init.d/lightdm missing LSB information update-rc.d: see &lt;http://wiki.debian.org/LSBInitScripts&gt;  Disabling system startup links for /etc/init.d/lightdm ...  Removing any system startup links for /etc/init.d/lightdm ...    /etc/rc0.d/K20lightdm    /etc/rc1.d/K20lightdm    /etc/rc2.d/K80lightdm    /etc/rc3.d/K80lightdm    /etc/rc4.d/K80lightdm    /etc/rc5.d/K80lightdm    /etc/rc6.d/K20lightdm  Adding system startup for /etc/init.d/lightdm ...    /etc/rc0.d/K20lightdm -&gt; ../init.d/lightdm    /etc/rc1.d/K20lightdm -&gt; ../init.d/lightdm    /etc/rc6.d/K20lightdm -&gt; ../init.d/lightdm    /etc/rc2.d/K80lightdm -&gt; ../init.d/lightdm    /etc/rc3.d/K80lightdm -&gt; ../init.d/lightdm    /etc/rc4.d/K80lightdm -&gt; ../init.d/lightdm    /etc/rc5.d/K80lightdm -&gt; ../init.d/lightdm $ sudo shutdown -r 0   and the gui is back up and running again after the reboot! so this clearly did not have the desird effect. however:  $ sudo /etc/init.d/lightdm stop   kills the gui. moving to tty2 (by pressing ctrl+alt+f2) and attempting to open firefox:  $ firefox &amp; Error: no display specified   so attempting to specify a display:  $ export DISPLAY='0.0' $ firefox &amp; Error: cannot open display: 0.0   and now i'm stuck. i can still get the gui back on ctrl+alt+f7 by entering the following into tty2:  $ sudo /etc/init.d/lightdm start   but this is not what i want. i just want to be able to run firefox without showing all the other desktop things such as the clock and the menu bars, etc.  trying out some of the things in ' answer  $ sudo /etc/init.d/lightdm stop $ echo "#!/bin/bash" &gt; ~/.xinitrc $ echo "exec firefox" &gt;&gt; ~/.xinitrc $ xinit   this does exactly what i want :)
86115
I am working on automating a maintenance routine that involves starting and stopping a script that is running in a screen session.  My approach is to kill the screen session, and then restart it and run the command from within a script using the abilities to both create a screen and pass a command without needing to attach to the screen.  However, I am having difficulties with this.  I can create the screen correctly without it attaching using screen -d -m -S screen_name.  However, if I run a command based on:  screen -S screen_name-X stuff "command 1"'echo -ne '\015''"command 2"'echo -ne '\015''  with the echo -ne '\015' being wrapped with backticks rather than single quotes.  It is to simulate the user pressing the enter key as the commands I use are moving to a directory and executing a script located there.  This command works, but only if the screen has been attached to once it has been created.  As I am trying to automate the process of creating the screen and running the commands within it I would like to avoid having to attach and detach within a script.  I will be trying the suggestion of creating a shell script containing the commands I need to execute within the screen and edit according to my results.  Is there a way to create a screen and run a command within the screen either in one command, or without having to attach to the screen after creating but before execution of the command?  Thanks in advance.  **Update - having tried the suggestion to place the commands I need to execute within a shell script I have been able to successfully create a screen and execute the commands from within the screen, but I am getting the behaviour that when the script stops running the screen closes as well.  This shouldnt be a problem as the script is a logging script that should only stop with the knowledge of the sys admin or through the script I am trying to develop, however it would be preferable to have the screen setup in such a way that the screen does not disappear if the script is stopped.  Is it possible to achieve this behaviour? **
43827
The following crontab does not work:  # TEST LINE DOES DOT RUN */1 * * * * /bin/echo 'test '`/bin/date +%Y-%m-%d` &gt;&gt; /tmp/test   I also tried starting it with:  SHELL=/bin/bash   Update: I thought the backtick characters ` were the villains, but as the answer below clarifies the percentage % was the culprit!
63527
I have a simple periodic cron task that must run as root. I want to use Zenity (or similar) to display a GUI informational dialog to user 1000 (or logged in user or all users) when the cron task finishes.   I'm looking for a simple, easy, quick solution. I'll adapt to the requirements of such a simple solution.  Here's where I am so far. My bash script works fine if run manually, but when Anacron runs it, nothing happens and I see Gtk-WARNING **: cannot open display in the logs. I hoped it would display my dialog to the user after being run by cron.  I realize (after reading related questions) that cron needs to be decoupled from the GUI. If user 1000 is not logged in, I could take one of several options:   do nothing (possibly acceptable because I want to keep it simple) display the dialog with completion message to the user when they log in next time (best) display some other type of notification (NOTE: the computer is a desktop system without a mail server installed)   I found these related questions: x11 - Anacron job complains "Gtk-WARNING **: cannot open display" - Unix &amp; Linux Stack Exchange   shell - How to pass data outside process for zenity progress? - Unix &amp; Linux Stack Exchange   Example Code (from other question which is essentially the same as mine):  #!/bin/bash # Backs up the local filesystem on the external HDD  sleep 60  DISPLAY=:0.0  zenity --question --text "Do you want to backup? Be sure to turn on the HDD." if [ $? -ne 0 ]     then exit 1 fi  *Do backup stuff here*   Error:  (zenity:9917): Gtk-WARNING **: cannot open display:  run-parts: /etc/cron.daily/backup-on-external exited with return code 1   (I'm running Kubuntu, so a KDE solution would be even better than Zenity, but I already installed Zenity, so I can keep using it.)
51391
Is there a way to add lines to a user's cron via script?  I usually do it using crontab -e, but I would like to automate this task with a shell script.
10006
I have a shell script. I want to configure my script to run automatically during startup. I know how to do this from GUI. But I wanted to do this from terminal. How can I do this?  On a primary research I found that the file needs to be moved to /etc/int.d/ directory. But this operation needs sudo permission. I wanted to do this without super user permissions.   I also found that there are files under ~/.config/autostart/ which are having some settings regarding the startup applications. But I don't know how to edit them to achieve this.   Can someone tell me the exact procedure to achieve this?
24002
I need my script to be executed a minute after each reboot. When I apply @reboot in my crontab it is too early for my script - I want the script to be executed after all other tasks that are routinely run on reboot. How might I run the script sometime after reboot?
92759
I'm trying to ensure a script remains running on a development server. It collates stats and provides a web service so it's supposed to persist, yet a few times a day, it dies off for unknown reasons. When we notice we just launch it again, but it's a pain in the rear and some users don't have permission (or the knowhow) to launch it up.  The programmer in me wants to spend a few hours getting to the bottom of the problem but the busy person in me thinks there must be an easy way to detect if an app is not running, and launch it again.  I know I could cron-script ps through grep:  ps -A | grep appname   But again, that's another hour of my life wasted on doing something that must already exist... Is there not a pre-made app that I can pass an executable (optionally with arguments) and that will keep a process running indefinitely?  In case it makes any difference, it's Ubuntu.
1708
I am new to linux and I read and followed many instructions to run a python script at reboot but non of them worked:  this is the command I want to run:  /usr/bin/python3 /home/am/projects/AMAcc/map.py   I used crontab -e and added   @reboot /usr/bin/python3 /home/am/projects/AMAcc/map.py   I tried sudo crontab -e and added the same command  I even edited /etc/crontab file and added above command.   Tried adding #!/usr/bin/python3 at top of my python code and changing its permissions like: sudo chmod a+x map.py  As documents suggested that all users would be able to run cron jobs if cron.deny file exists but its empty, so I tried creating empty cron.deny files in both /etc/cron.deny and /usr/lib/cron/cron.deny. But still no luck running the cron job.  What am I doing worng?
33536
There is a directory in System/Library for startup items I presume: StartupItems  I need to have a shell script that will configure ethernet interface at start up, with local network address and subnet mask. I need to do this because the network preferences for configuring the ethernet interface will NOT set it using manual settings. THIS appears to be a serious bug, or my installation is bad.  I was given the advice to use  networksetup from the command line but that will not configure the ethernet interface in such a way that the configurations will be there on reboot.  The script needs to do its work with root privileges, or with sudo, but I am assuming that if it uses sudo, there will be a password dialog presented at boot time when the boot process gets to that script.  (I have had enough experience with FreeBsd and Linux to find my way around in the terminal, but not necessarily as it applies to Mac OSX)
80164
Is it possible to make a bash script that starts tmux and split the screen horizontally and runs watch -n1 tail -n5 file_n in each ? Basically I'm starting a script multiple times and write its progress into different files that I'd like to monitor. Would be nice if I could run that from one script as opposed to manually open 10 files by myself. I never used tmux btw that's why I'm asking this.
14169
I want to monitor a file. So I have tailed a file using below command, to execute a script per line.  tail -3f logfile.log | grep "action.*add" | sed -u -e "s/^/'/" -e "s/$/'/" | xargs -L 1 -P 5 bash testscript.sh   But it seems that script is not getting executed.  I observed that grep is not giving any input for next pipe.  When I tried,  tail -3f logfile.log | grep "action.*add"   it worked. But when given next filter like sed, grep, xargs etc. It didn't worke like the one shown below.  tail -3f /var/tmp/rabbitmq-tracing/logfile.log | grep "action.*add" | grep add    Please help me to know why this is happening and how to overcome this.    Edit 1: Basically anything like below should work and it was working previously. Confused why it is not working now.  tail -f file.txt | grep something | grep something | grep something     EDIT 2: Output line after first grep will be a json string like below. And I want to give this line as input( enclosed in single quotes) to bash script.  {"twNotif": {"originator": "api", "chain": "test", "txId": "08640-0050568a5514", "version": "1.0", "msgType": "api", "twData": {"api": {"hostId": "007bdcc5", "user": "test", "cmdTxt": "100599"}}, "action": "add", "store": "test", "msgTime": 1467280648.971042}}