LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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, 09: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 09:38 AM.
 
Old 10-19-2009, 09: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 10:59 AM. Reason: Gramatical correction.
 
Old 10-19-2009, 10: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, 10: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


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


All times are GMT -5. The time now is 09:02 PM.

Main Menu
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