Redirecting output of a command to a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Redirecting output of a command to a file
# 1  
Old 04-13-2009
Redirecting output of a command to a file

Hi

We are having a requirement where one shell script, say a.sh (which uses Java and connects to Oracle database using JDBC) keeps on running everytime. I created a wrapper (to check whether a.sh is running and if not then to start it) and scheduled it in the crontab. Now all the output from this script gets written to the mail file of the user.

To avoid the whole stuff being written to the mail file, i thought about re-directing the same to some log files (generated on the daily basis). I tried this:

Code:
#!/bin/sh
a=`ps -ef|grep repgen.sh|grep -v grep|wc -l`
b=`/usr/bin/date +"%d%m%y"`
if [ $a -lt 1 ]; then
sh /dit/scheduler/bcp/repgen.sh 1>>/dit/scheduler/bcp/$b.log1 
2>>/dit/scheduler/bcp/$b.log2
fi

But now the issue is, if a.sh keeps on running without any issues, wrapper doesn't find anything to do and the the output keeps on getting appended to the very first logfile (logfile when first time a.sh started). Is there a possible way out so that i can generat logs in files created for everyday.

Thanks & Regards
Ankit Goel
# 2  
Old 04-13-2009
hi,
why don't add a else to your script?
Bye
# 3  
Old 04-13-2009
Hi
Suppose that the code is written in the file a.sh.
Now the crontab has a entry
* * * * * /dit/scheduler/bcp/a.sh
Every minute it checks whether a.sh is running or not.

Now suppose that the the wrapper started today.The log file name will be
130409.log1.Now i want that the next day i.e tomorrow the log file should be generated with the name 140409.log1.

Thanks & regards
Ankit Goel
# 4  
Old 04-13-2009
Try this:

Code:
command >> $(date '+%d%m%y').log1

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirecting output to file

Hi, I have created script which redirect the output to file.I am able to get the output in file but not in the format. Output :Content of the log which have 10 -15 lines. Actal :Line1 ..Line 2Line3 Line4 Line 5 Expected:Line1 Line 2 Line3 Please... (7 Replies)
Discussion started by: karthik771
7 Replies

2. Programming

Redirecting output to new file for command "perldoc perllocal"

Hi, I have to redirect output of the command "perldoc perllocal" to new file which contains all the perl module installed. Currently using perldoc perllocal >> mod_data This does not contain all perl modules installed locally on machine, and each character is doubled. Please... (3 Replies)
Discussion started by: asak
3 Replies

3. Linux

RHEL 6.3 - chage command not redirecting the output to console.

When i am issuing chage command, it reporting the output properly. But when i redirect the output, i am not getting the output in the mentioned path. chage -l root >> /tmp/chage.txt. I need to use this into the script to capture the data. I think its seems to be bug with RHEL 6.3. Same... (3 Replies)
Discussion started by: Srini.rk1983
3 Replies

4. Shell Programming and Scripting

Redirecting command output to a file in a shell script

Hello All, I have some unique requirement. I have written a very lengthy script which calls number of resource script to execute a particular task. What I want is output of each command(called from main script and resource scripts) should go to a... (3 Replies)
Discussion started by: anand.shah
3 Replies

5. Shell Programming and Scripting

Redirecting output to file

Hi, Below is the whole string which is to be redirected to the new file. su - oracle -c "exp $user/$pass file=/oracle/oradata/backup/exp_trn_tables_`date +%d_%b_20%y_%H_%M_%S`.dmp log=/oracle/oradata/backup/exp_trn_tables_`date +%d_%b_20%y_%H_%M_%S`.log tables=table1,table2 statistics=none" ... (3 Replies)
Discussion started by: milink
3 Replies

6. Shell Programming and Scripting

Redirecting output to both console and to a file

Hi All, Is there a way in Bash we can redirection some output to both console and the file at the same time. ~Parag (2 Replies)
Discussion started by: paragkalra
2 Replies

7. Shell Programming and Scripting

Redirecting command output as well as commands

I have a Bourne Shell script that is normally run as a background job and redirects it's output to a file internally (using exec >>); I use "set -x" to capture each command which provides me with a nice shell execution log if it all goes to pieces. I now also need to be able to also run this as... (4 Replies)
Discussion started by: AncientCoder
4 Replies

8. Shell Programming and Scripting

problem redirecting output of command to variable

Hi. I'm a newbie in scripting and i have this problem: i want to use the 'fuser' command on a file to tell if it's being accessed (for my purposes: still being written). I want to save the output of the command and later compare with the 'not being used' result. the script: #!/bin/bash... (2 Replies)
Discussion started by: nunovc
2 Replies

9. Shell Programming and Scripting

Redirecting <talk> output to a file

Is it possible to run <talk> such that both sides of the conversation are written to the screen and also to a file? I use the utility to chat with collaborators and sometimes it would be nice to have a record of our conversation while we are problem solving. I am running OS X, so <talk>... (4 Replies)
Discussion started by: cej
4 Replies

10. UNIX for Dummies Questions & Answers

Redirecting output file to a different server.

Hi, I hope this is problem makes sense and that someone can offer some advice. Basically i have a perl script which accesses a database and outputs the information to a file. Is it possible to use a 'system' command to embeb some Unix command which moves that file to another directory... (3 Replies)
Discussion started by: Stormrider
3 Replies
Login or Register to Ask a Question