LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 02-20-2006, 01:00 PM   #1
Scalpel4
LQ Newbie
 
Registered: Feb 2005
Distribution: Suse 9.2
Posts: 13

Rep: Reputation: 0
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.
 
Old 02-20-2006, 01:11 PM   #2
pljvaldez
Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Squeeze (x86)
Posts: 6,092

Rep: Reputation: 269Reputation: 269Reputation: 269
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.
 
Old 02-20-2006, 01:17 PM   #3
Scalpel4
LQ Newbie
 
Registered: Feb 2005
Distribution: Suse 9.2
Posts: 13

Original Poster
Rep: Reputation: 0
Thanks. Will this overwrite the output file or append to it?
 
Old 02-20-2006, 01:34 PM   #4
pljvaldez
Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Squeeze (x86)
Posts: 6,092

Rep: Reputation: 269Reputation: 269Reputation: 269
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.
 
Old 02-20-2006, 01:55 PM   #5
Scalpel4
LQ Newbie
 
Registered: Feb 2005
Distribution: Suse 9.2
Posts: 13

Original Poster
Rep: Reputation: 0
Good to know! Thanks! I'll try the script and see what I can get.
 
Old 02-20-2006, 02:01 PM   #6
pljvaldez
Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Squeeze (x86)
Posts: 6,092

Rep: Reputation: 269Reputation: 269Reputation: 269
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!
 
Old 02-21-2006, 12:49 PM   #7
Scalpel4
LQ Newbie
 
Registered: Feb 2005
Distribution: Suse 9.2
Posts: 13

Original Poster
Rep: Reputation: 0
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?
 
Old 02-21-2006, 01:29 PM   #8
titopoquito
Senior Member
 
Registered: Jul 2004
Location: Ruhr Area, Germany
Distribution: Slackware64 14.0
Posts: 1,525

Rep: Reputation: 94
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.
 
Old 02-21-2006, 01:31 PM   #9
Scalpel4
LQ Newbie
 
Registered: Feb 2005
Distribution: Suse 9.2
Posts: 13

Original Poster
Rep: Reputation: 0
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.
 
Old 02-21-2006, 01:36 PM   #10
pljvaldez
Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Squeeze (x86)
Posts: 6,092

Rep: Reputation: 269Reputation: 269Reputation: 269
Google for vim, crontab googling won't give you much in the way of commands to use vim...
 
Old 02-21-2006, 01:39 PM   #11
pljvaldez
Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Squeeze (x86)
Posts: 6,092

Rep: Reputation: 269Reputation: 269Reputation: 269
Or better yet:
Code:
export EDITOR=/bin/nano
If you like nano (it's pretty easy) you can add it to your /etc/profile...
 
Old 02-21-2006, 05:47 PM   #12
Scalpel4
LQ Newbie
 
Registered: Feb 2005
Distribution: Suse 9.2
Posts: 13

Original Poster
Rep: Reputation: 0
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.
 
Old 02-21-2006, 05:50 PM   #13
pljvaldez
Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Squeeze (x86)
Posts: 6,092

Rep: Reputation: 269Reputation: 269Reputation: 269
I'm not familiar with qshape, but is there a way to point it to the queue files in the script?
 
Old 02-21-2006, 06:08 PM   #14
Scalpel4
LQ Newbie
 
Registered: Feb 2005
Distribution: Suse 9.2
Posts: 13

Original Poster
Rep: Reputation: 0
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
 
Old 02-21-2006, 06:29 PM   #15
mbreith
Member
 
Registered: Feb 2006
Location: oregon
Distribution: PIII fedora2 | P4 fedora2 | Thinkpad fedora2
Posts: 54

Rep: Reputation: 15
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving the output of a file as a variable mrobertson Programming 5 07-08-2005 01:43 AM
IPTables: config files, scripts, saving etc...confused tarballed Linux - Security 4 12-30-2004 07:41 PM
MRTG getting output from scripts ivanatora Linux - Software 1 08-12-2004 06:23 AM
have apache deliver the output of perl cgi scripts immidiately fibbi Linux - Software 2 07-13-2004 01:17 PM
Saving gcc output files to new directory Fe98 Programming 3 12-08-2003 08:18 AM


All times are GMT -5. The time now is 01:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration