If you want crontab to run without sending email, make the command not generate any output. Many commands have a -q or --quiet switch to make them not generate output. Otherwise you can redirect the output to a file or /dev/null.
some_command arg1 arg2 >/dev/null 2>/dev/null
But instead of using cron, if you are willing to accept sloppy timing, you can just keep one script running constantly and put it to sleep for a minute.
#!/bin/bash
while true; do
some_command arg1 arg2
sleep 60
done
This assumes you have it running in a dedicated shell and you stay logged in. But if you want to log out and let run, you can use screen (install the screen package if you don't have it--it's quite valuable).
sorry, I must be thick-sculled - I'm having hard time parsing this sentence.
Chris, could you elaborate a little bit more and why your other suggestion is any better.
In 2 words or less.....
my bad - you're absolutely right. Somehow I thought that the original 'some_command' was being spawned in the background as well. Sorry - too much egg-nock I reckon.
But at the same time....
while :
do
sleep 60 & pid=$!
some_command arg1 arg2
wait $pid
done
if 'some_command' takes longer than 60 sec to run, this implementation is not the same as it would have been if cron-ed.
But if we put the 'some_command' in the background, it would be the same.
Not sure what the OP's intentions are though.
Cool! Cfajohnson, you taught me two new things here. However,
While I am pleased to learn about the nohup command, I still contend that the screen command is extremely valuable. If the command being executed spits out anything interesting, you may not want it emailed to you every minute, but if you let it go to the screen, you can view it from any computer you can ssh from.
I've used screen a couple times to start a bit-torrent download of a large .iso file on my home computer while I was at work. It's nice to be able to leave it running in the terminal while the terminal is floating unattached and then to be able to reattach it to take a look from any computer at home or work.
lets take 'some_command' takes 120 secs to run ( > 60 ) and in this case ( sample posted in the thread ), wait - waiting for $! will be activated and once again its back in the 'while' loop
same is the case for a cron-d
it doesn't check whether previous instance instantiated has completed or not, its job is to spawn instance every 'n'th minute.
end of 1st minute - one instance will be running
end of 2nd minute - first instance will be terminated
second instance started
end of 3rd minute - second instance still running
third instance spawned
and so on ...
first of all i would like congratulate for participating this thread and made your own valuble opinoin. I am really impressed and heading to get a proper solution.
I just want to know in the below code- pid=$i --> what exactly means by that? I will then implement it in my systme.
while :
do
sleep 60 & pid=$!
some_command arg1 arg2
wait $pid
done
as the above code work as same like cron-d means if som_command take more than 60 second to execute meanwhile whithin 60 seconds some_command will again execute.
which means assign the process id of the 'last' run background process to pid which is then used by wait call for the return of sleep command initiated