stdout redirect is working buy direct script exec but not in cron


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting stdout redirect is working buy direct script exec but not in cron
# 1  
Old 06-25-2010
[SOLVED] stdout redirect is working buy direct script exec but not in cron

Hi @ all Smilie

i made a very little shell script witch is working well when i'm launching it directly

like with ./script

but when i'm launching it by cron tab it work at half only.

the part of the script witch are not working are:

Code:
#!/bin/sh

apt-get updade
apt-get -s upgrade >> /var/log/upgrade.log 2>&1

when i'm launching this "by hand" it's working well and i have the result in the log file, but when i would start the script b a crontab the log file is empty

is someone have an idea ?

the second thing is i'm launching (by cron always) another script in background.
the script is working well and do his job but the output redirecting in a file not. The file stay empty too.

I'm using this sentence: (it's in a php file launched by crontab)

Code:
system("the_file_path/script.sh >>/var/log/my_log.log 2>&1 &");

also if someone have an idea, or a way to prospect Smilie i'll be happy

thanks
calibal

Last edited by calibal; 06-28-2010 at 06:19 AM.. Reason: solved thread
# 2  
Old 06-25-2010
It might not be related but shouldn't you replace 2&1 by 2>&1?
# 3  
Old 06-25-2010
it had misstyped the forum's thread there is 2>&1 in the scripts (i correct the 1rts post)

thanks for your answer Smilie

i also tryed with others reidrecting args in the past, but same result.

like
Code:
apt-get -s upgrade &> /var/log/mylog.log

# 4  
Old 06-25-2010
Well I remember I had once a problem with the crontab because I was not using absolute paths like /usr/bin/apt-get.
Maybe the redirection is not a problem?
Maybe the program is not executed at all?
# 5  
Old 06-25-2010
yesss thanks, so logic it works Smilie thanks a lot.

i just have to found why the second part is not writing anything.
Code:
system("the_file_path/script.sh >>/var/log/my_log.log 2>&1 &");

# 6  
Old 06-28-2010
it was just a right acces isssue :s
the script was launched by a user who does'nt have acess to var log
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script not working in cron but working fine manually

Help. My script is working fine when executed manually but the cron seems not to catch up the command when registered. The script is as follow: #!/bin/sh for file in file_1.txt file_2.txt file_3.txt do awk '{ print "0" }' $file > tmp.tmp mv tmp.tmp $file done And the cron... (2 Replies)
Discussion started by: jasperux
2 Replies

2. Shell Programming and Scripting

Script Variables Inquiry, Values Okay in Standalone Exec, No-Show in Cron Exec

I have the following bash script lines in a file named test.sh. #!/bin/bash # # Write Date to cron.log # echo "Begin SSI Load $(date +%d%b%y_%T)" # # Get the latest rates file for processing. # d=$(ls -tr /rms/data/ssi | grep -v "processed" | tail -n 1) filename=$d export filename... (3 Replies)
Discussion started by: ginowms
3 Replies

3. Shell Programming and Scripting

Been working since 25+ hrs: Bash Script to rename files supposedly direct but difficult to execute

:wall::wall::wall: Hi I have horrible script below, need help in renaming ls -l output into new filename format: Desired output: cp -pv original_path/.* newDirectory/owner_of_file.%dd%mm%y.file_extension.first_8_characters_of_original_filename localuser@localuser:~ vi... (3 Replies)
Discussion started by: wolf@=NK
3 Replies

4. Shell Programming and Scripting

Script is not working from cron while working manually

Hello, I am facing a very strange problem when I run my script manuallu ./Fetchcode which is using to connect with MKS integrity from linux end it workks fine but when I run it from cron it doesn't work.Can someone help me 1) How could I check my script when it is running from cron like... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

5. Programming

how to redirect back to stdout

In my program, I am using library provided by other. In the library, the cout/cerr is redirected to a file (the file path is known). After I call some methods in the library, I get one side-effect --> The cout/cerr in my own program is also directed to the file. So how can I to redirect... (5 Replies)
Discussion started by: princelinux
5 Replies

6. Programming

redirect stdout

hello again! i use dup2 to redirect stdout. I run what i want, now i want undo this redirection. how can i do that? thanx in advance (7 Replies)
Discussion started by: nicos
7 Replies

7. Shell Programming and Scripting

How to redirect stderr and stdout to a file

Hi friends I am facing one problem while redirecting the out of the stderr and stdout to a file let example my problem with a simple example I have a file (say test.sh)in which i run 2 command in the background ps -ef & ls & and now i am run this file and redirect the output to a file... (8 Replies)
Discussion started by: sushantnirwan
8 Replies

8. Shell Programming and Scripting

Script that Redirect SSH output via cron

Hi, I have a script that's being called via a crontab which is a wrapper script that creates a log for the script that gets executed. Within the script that gets executed, it also run's subscripts. I've been able to get everything to work .. but the issue is one of the subscript that goes out... (4 Replies)
Discussion started by: primp
4 Replies

9. UNIX for Advanced & Expert Users

problem with redirect stdout to file

Hi all hope you can help as I am going MAD!!! :eek: The below is in a shell script but the redirection in the sed line does not work and outputs to the screen and the $fname_2 does note get created ????? Can any one help ?? #!/bin/ksh cd /app/ for fname in `ls -1 X*` do sed 1d $fname... (3 Replies)
Discussion started by: mlucas
3 Replies

10. Shell Programming and Scripting

Redirect stdout and stderr

How can I redirect and append stdout and stderr to a file when using cron? Here is my crontab file: */5 * * * * /dir/php /dir/process_fns.php >>& /dir/dump.txt Cron gives me an 'unexpected character found in line' when trying to add my crontab file. Regards, Zach Curtis POPULUS (8 Replies)
Discussion started by: zcurtis
8 Replies
Login or Register to Ask a Question