Slightly newb - autolaunching, scripts, and saving output
Thanks to anyone who can help. I know nothing about scripting, but I know it's what I need here.
I need to create a script that will run once per minute for a one hour period. The script will only need to run qshape, but it will need to take the qshape output and append it to a text file. I need to know how to write the script, and how to output the console messages to a text file. |
I'm a slight newbie myself, but here's the gist:
1) Create a script 2) create a cronjob with the output going to a file. If you know what you type from the command line, your script generally looks like: Code:
#!/bin/sh Then to create a cronjob, type crontab -e and set it to run at the appropriate time: * 6 * * * $HOME/script.sh >> $HOME/script.out 2>&1 This should run the script every minute for the 6 AM hour of everyday. The fields are minute, hour, day, month, day of week. See man crontab. The 2>&1 should output both errors and STDOUT. |
Thanks. Will this overwrite the output file or append to it?
|
One ">" means overwrite, two ">>" means to append. You can try it from the command line just to make sure, just type ls -l >> ls.txt a couple three times and then look at the file.
|
Good to know! Thanks! I'll try the script and see what I can get.
|
You might have to adjust the crontab values a bit. I'm sort of guessing that * will work for the minutes section. It might be that you have to use */1 (which means in increments of 1) for the minutes tab or 0-59. Anyway, good luck!
|
OK, here's what I come up against. I am logged in as root when I do this, so that's not the cause. When I run crontab -e, it won't let me edit, just view. Running Suse 9. Any thought anyone?
|
Your crontab table is probably opened with vim. You have to use vim commands to get in insert (edit) mode.
Try exiting the crontab table by typing ":q" and press Return key. If this gets you back to command line search for an tutorial for vim. Or type vimtutor which should give you a tutorial of about 30 minutes. |
There you go! I have officially announced myself to the world as a newb! Thanks! I'll google crontab and look for a list of commands.
|
Google for vim, crontab googling won't give you much in the way of commands to use vim...
|
Or better yet:
Code:
export EDITOR=/bin/nano |
Next and hopefully final question.
Script written, runs perfectly in console. Cronlog running the script when I tell it to. This is the script: date >> test.txt 2>&1 qshape.pl >> test.txt 2>&1 I get "Command not Found" when cronlog runs the script. When I put in \urs\sbin\qshape.pl instead, qshape runs but cannot find the queue files. |
I'm not familiar with qshape, but is there a way to point it to the queue files in the script?
|
Found this, http://www200.pair.com/mecham/spam/s...r20050626.html
I'll give it a shot and let you know tomorrow. vi /etc/cron.d/qshape-cron And insert (2 lines): PATH=/usr/sbin 31 7 * * * postfix /usr/sbin/qshape incoming active deferred 2>&1 |/usr/bin/mail -s "qshape sfa" root |
Quote:
It also looks like the slashes are going in the Windows direction. Is this intentional? |
All times are GMT -5. The time now is 01:36 AM. |