Redirection of output to a log file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Redirection of output to a log file
# 1  
Old 08-21-2008
Redirection of output to a log file

Apologies for the trivial nature of this question but I cannot seem to get a simple re direct to a log file to work

Step 1
touch log.txt
at -f batch.sh now >> log.txt

I am trying to get the batch.sh contents into the log file

Manny Thanks
# 2  
Old 08-21-2008
The touch command isn't necessary, the file is created if it's not present.
Does your script echo the messages to stdout/stderr? Try to redirect both the output to the file:

Code:
at -f batch.sh now >> log.txt 2>&1

Regards
# 3  
Old 08-21-2008
Thanks for the help so far. I now get output in the log but just the
job time and date message. I need the output from the run of batch.sh

Regards
# 4  
Old 08-21-2008
Right... at is a batch program which will queue the process and run it at a future point in time. Redirecting NOW doesn't redirect the output later. (Redirection is a shell function). "at", however, will save the program's output to a file and email it to you. So check in Mail (or make sure email is properly setup for forwarding.) If you don't want email, then do this at the beginning of the script:

Code:
# ... initialization of your script
exec >$HOME/script-output.$$ 2>&1
# rest of your script

If you want to append to the same file everytime, do this instead:

Code:
# ... initialization of your script
exec >>$HOME/script-output.log 2>&1
# rest of your script

# 5  
Old 08-21-2008
What output? Any output of your script should be in the file now....
Post the contents of batch.sh.

Regards
# 6  
Old 08-21-2008
all that batch is doing in this instance is

/dev/vg00/lvol3 2097152 299240 1784336 14% /
/dev/vg00/lvol1 1048576 140264 901320 13% /stand
/dev/vg00/lvol21 2097152 127451 1857821 6% /webservers
/dev/vg00/lvol8 4784128 2101952 2661592 44% /var
/dev/vg00/lvol9 2097152 16982 1950167 1% /var/adm/crash
/dev/vg00/lvol7 6356992 5681080 670680 89% /usr
/dev/vg00/lvol12 1572864 645992 868997 43% /usr/cache
/dev/vg00/lvol4 262144 9960 250264 4% /tmp

this is what i need in the log
# 7  
Old 08-21-2008
So in your script, you just need to do this:

Code:
#!/bin/sh
df 2>&1 | tee -a logfile.log

Now the output will be see both in the logfile and in your email.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command output redirection to file issues

Hi, I have a peculiar issue w.r.t redirecting the command output to a file when using loop. I am redirecting command output to same file in a series of if condition statements, but if one block of if condition statement writes the log to the file , the subsequent block of if condition... (7 Replies)
Discussion started by: ananan
7 Replies

2. Shell Programming and Scripting

output redirection

Hi all I was wondering if there was a slicker way of doing this without the file - awk '{print $2}' FS=":" "${FILE}" > "${TMPFILE}" { read M_GRP_ID || m_fail 1 "Error: Read failed 1 (${FUNCNAME})" read M_GRP_WAIT || m_fail 1 "Error: Read failed 2 (${FUNCNAME})" }... (6 Replies)
Discussion started by: steadyonabix
6 Replies

3. Shell Programming and Scripting

Output redirection of c binary file to a file in shell script is failing

I am struck up with a problem and that is with output redirection. I used all the ways for the redirection of the output of c binary to a file, still it is failing. Here are the different ways which I have used: ./a.out | tee -a /root/tmp.txt 2>&1 ./a.out | tee -a /root/tmp.txt 1>&1 ./a.out |... (2 Replies)
Discussion started by: Maya29988
2 Replies

4. Shell Programming and Scripting

output redirection to existing file question

So I have a existing file that I used the uniq command on and I need to save the output to the same file without changing the file name. I have tried $ uniq filename > filename then when I cat the file it then becomes blank like there is nothing inside. any help would be much appreciated... (0 Replies)
Discussion started by: drew211
0 Replies

5. Shell Programming and Scripting

Output redirection

We have an application here that does some table queries and then prints the result on screen. I do not have the code of this application (which i will just call "queryCommand"), but what it does is that you call it with some parameters and it prints some info about the query and then the... (5 Replies)
Discussion started by: jolateh
5 Replies

6. Shell Programming and Scripting

Redirection output

Hi there I have a script that runs but it outputs everything onto the screen instead of a file. I've tried using the > outputfile.txt however all it does is dump the output to the screen and creates an outputfile.txt but doesn't put anything in that file. Any help would be appreciated ... (6 Replies)
Discussion started by: kma07
6 Replies

7. Shell Programming and Scripting

awk output redirection to file

I have a system stat command running which generates data after 5 sec or so. I pass this data to awk and do some calculation to present the data differently. Once done now I want to pass this data to file as and when generated but doesn't work..unless the first command completes successfully.... (6 Replies)
Discussion started by: learnscript
6 Replies

8. UNIX for Dummies Questions & Answers

Capping output redirection log file length

I am trying to write a script which will output notifications to a logfile, but I would like to cap the logfile to, let's say, 200 lines. Specifically I am using custom firmware, DD-wrt, on my router and I am implementing a script to connect to my work vpn. I have a loop that pings a computer... (2 Replies)
Discussion started by: joemommasfat
2 Replies

9. UNIX for Dummies Questions & Answers

Output file redirection

Suppose I have a file named a When I write cat a>a The following error message is displayed cat: a: input file is output file and my file a is truncated to zero size. Also the exit status of the last command is 1 Can someone tell me what actually happens when I do so? (1 Reply)
Discussion started by: aagajaba
1 Replies

10. Shell Programming and Scripting

Remote server file output redirection

Hi, I want ssh to the remote server and then execute ls and redirect the output to the file in remote server itself like ssh root@$server `ls /var/log/users.txt > root@$server:/home/users.txt` Can you please let me know the correct syntax for it. Thanks in advance (2 Replies)
Discussion started by: mohitmoudgil
2 Replies
Login or Register to Ask a Question