Did you really mean to put the \
at the end of the line? If not then try removing those - they escape the following character.
also, dropping the -X
helps the setup work for me, for instance:
screen -S test -d -m -X touch /tmp/test
fails with No screen session found
, however:
screen -S test -d -m touch /tmp/test
works fine. As such I suspect the following will work for you:
#!/bin/bash
screen -S test -d -m $HOME/folder/folder/.program
screen -S test2 -d -m $HOME/folder/folder/.program2
Remember, that if you run this at boot time, $HOME is not the same as after you log in as a specific user. If you need to run it as a certain user you'll need to use the likes of su
to run it as that user, and specifying the full path will remove any ambiguity:
#!/bin/bash
screen -S test -d -m su - username /home/username/folder/folder/.program
screen -S test2 -d -m su - username /home/username/folder/folder/.program2
Or, you would call the entire script above as su - username /path/to/your/script
.
cron
does not know where to find mkdir
. So if you do not include a PATH
in your cron then always use absolute paths. This works:
0 12 * * * /bin/mkdir /path/to/folder
Have a look at the part starting with using cron
in the link. You can put a path and other variables at the top of cron
like so:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
That way you have access to /sbin/
, /bin/
, /usr/sbin/
and /usr/bin/
.
I myself prefer to only include a script in cron
and set the commands inside that script.
Best Answer
Note: The original poster asked 'how can i do this in cron'. I've updated the response to address that.
Get the 'inscreen' script and put it in
~/bin/
:create a screen session named 'cronjobs':
screen -d -m -S cronjobs
You'll have to arrange for that to happen on each boot, or add '--new-if-needed' to each crontab entry below.
Add entries in cron using
inscreen
, crontab looks like:The above will: