LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Slightly newb - autolaunching, scripts, and saving output (https://www.linuxquestions.org/questions/linux-newbie-8/slightly-newb-autolaunching-scripts-and-saving-output-417614/)

Scalpel4 02-20-2006 12:00 PM

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.

pljvaldez 02-20-2006 12:11 PM

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
whatever else you like | whatever other commands

Then save it and chmod +x it.

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.

Scalpel4 02-20-2006 12:17 PM

Thanks. Will this overwrite the output file or append to it?

pljvaldez 02-20-2006 12:34 PM

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.

Scalpel4 02-20-2006 12:55 PM

Good to know! Thanks! I'll try the script and see what I can get.

pljvaldez 02-20-2006 01:01 PM

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!

Scalpel4 02-21-2006 11:49 AM

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?

titopoquito 02-21-2006 12:29 PM

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.

Scalpel4 02-21-2006 12:31 PM

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.

pljvaldez 02-21-2006 12:36 PM

Google for vim, crontab googling won't give you much in the way of commands to use vim...

pljvaldez 02-21-2006 12:39 PM

Or better yet:
Code:

export EDITOR=/bin/nano
If you like nano (it's pretty easy) you can add it to your /etc/profile...

Scalpel4 02-21-2006 04:47 PM

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.

pljvaldez 02-21-2006 04:50 PM

I'm not familiar with qshape, but is there a way to point it to the queue files in the script?

Scalpel4 02-21-2006 05:08 PM

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

mbreith 02-21-2006 05:29 PM

Quote:

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
Would it put the output in /usr/sbin/test.txt ?
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.