Run a command as cron would but from the command line.
Posted
by BCS
on Stack Overflow
See other posts from Stack Overflow
or by BCS
Published on 2010-06-08T15:35:25Z
Indexed on
2010/06/08
17:02 UTC
Read the original article
Hit count: 238
I have a script that I'm trying to run from cron. When I run it from bash, it work just fine. However when I let cron do it's thing, I get a:
myscript.sh: line 122: syntax error: unexpected end of file
What I want is a way to run a command as if it was a cron job, but do it in my shell.
As a side note: does anyone know what would be differnt under cron? (the script already has a #!/bin/sh
line)
To answer my own question: I added this to my crontab:
* * * * * bcs for ((i=1; i <= 55; i++)) ; do find ~/.crontemp/ -name '*.run' -exec "{}" ";" ; sleep 1; done`
and created this script:
#!/bin/sh
tmp=$(mktemp ~/.crontemp/cron.XXXXX)
mknod $tmp.pipe p
mv $tmp $tmp.pre
echo $* '>' $tmp.pipe '1>&2' >> $tmp.pre
echo rm $tmp.run >> $tmp.pre
chmod 700 $tmp.pre
mv $tmp.pre $tmp.run
cat $tmp.pipe
rm $tmp.pipe
With that, I can run an arbitrary command with a delay of not more than one second.
(And yes, I know there are all kinds of security issue involved in that)
© Stack Overflow or respective owner