LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 10-19-2009, 08:25 AM   #1
laki47
Member
 
Registered: Feb 2009
Posts: 33

Rep: Reputation: 15
Crontab - redirecting script output - question


Hi!

I have question about output order in my manually created log file.

crontab -l:
0 * * * * /my/script/run.sh >/my/log/crontab.log 2>&1

Now, I have noticed that order in /my/log/crontab.log file is not same as command order.

i.e.

my run.sh script:

command1
command2
command3

in my crontab.log is

output_of_command1
output_of_command3
output_of_command2

Is this "normal"?

THX

edit:

command2 is ftp "here_document".

i.e.

my ftp script:

#!/bin/ksh
ftp -i server1 <<END
bin
lcd /dir1
cd dir2
mput *.*
!rm *.*
lcd /dir3
cd dir4
mput *.*
!rm *.*
END

my crontab.log file:

rm: *.* non-existent
rm: *.* non-existent
Local directory now /dir1
Local directory now /dir3

As you can see, first two ouputs are rm: (although in script they are at 2. and 4. place)
THX

Last edited by laki47; 10-19-2009 at 08:38 AM.
 
Old 10-19-2009, 08:47 AM   #2
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
The reason for this is that the output isn't written until the command is done. Your "rm" commands aren't being run before or after the ftp command, they are being run during the ftp command. They end first and are therefore written first. If you want the order to be the way you are looking for it, change your script to:

Code:
#!/bin/ksh
cd /dir1

ftp -i server1 <<END1
bin
cd /dir2
mput *.*
END1
rm *.*
cd /dir3
ftp -i server2 <<END2
bin
cd /dir4
mput *.*
END2
rm *.*
However, I don't really suggest doing this. If all you wanted to do was know why it is outputting things in an unexpected order, the reason is stated above.

HTH

Forrest

Last edited by forrestt; 10-19-2009 at 09:59 AM. Reason: Gramatical correction.
 
Old 10-19-2009, 09:09 AM   #3
laki47
Member
 
Registered: Feb 2009
Posts: 33

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by forrestt View Post
The reason for this is that the output isn't written until the command is done. Your "rm" commands aren't being run before or after the ftp command, they are being run during the ftp command. They end first and are therefore written first. If you want the order to be the way you are looking for it, change you script to:

Code:
#!/bin/ksh
cd /dir1

ftp -i server1 <<END1
bin
cd /dir2
mput *.*
END1
rm *.*
cd /dir3
ftp -i server2 <<END2
bin
cd /dir4
mput *.*
END2
rm *.*
However, I don't really suggest doing this. If all you wanted to do was know why it is outputting thins in an unexpected order, the reason is stated above.

HTH

Forrest
But commands are effectively (sorry I don't know "effectively" is the right word) executed in order they are written?
 
Old 10-19-2009, 09:12 AM   #4
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
They are run in the order written and the logs are written in the order the commands complete.

HTH

Forrest
 
  


Reply



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
Redirecting Input and Output in C/C++ sklitzz Programming 3 10-02-2009 06:18 AM
redirecting output into new script vortmax Linux - General 1 04-25-2008 03:16 PM
A little help with redirecting output tybalt Linux - Newbie 1 08-04-2007 10:08 PM
redirecting output using > cmk77 Slackware 8 11-10-2006 02:08 AM
Redirecting output of a shell script raj_deep2k1 Linux - General 2 01-20-2006 07:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:20 PM.

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
Open Source Consulting | Domain Registration