Is it possible to redirect a script output by command inside of that script?
I mean, if I have a script 'dosome.sh' I could run it by
I would dream to get some command inside of scrip to do the same; so, running the dosome.sh would have all output redirected to a log file
(Do not advise, please, put redirection to a log file from every command of that script. It is already unrealistical.)
So I would image something like that:
Iven would be greate to be able to do it the same as it would be done with 'tee' command: to have the output be written to file and in the same time to standard output, to screen, like in this command:
Appreciate any advice!
I could do that with "exec", but I couldn't get that work to write to a file and stdout simultaneously,
...
Please try exec options,
Thanks,
Nagarajan G
Thank you Nagarajan G!!
Exec works perfect to redirect from inside!
I try to get the print-out simultaneously and trying to do it with 'tail -f'
And I've get rock-n-roll:
to start 'tail' need and continue - need to run tail background (... & )
to stop 'tail' when it is done - need to know it's PID
but it is bad idea to kill 'tail' on end of screept - it could exit in a midle
so need to run monitoring of the script to stop the tail rigt after t'tail' start
Is this seems doable? Because by now I have some problem to get PID and kill it. (Actually I did it from outside script and get mess with PIDs)
Hi,
I managed to get that working using exec & pipes.The following is the script which i hope to work for you as well,
....
Please let us know if you could find a better approach
Thanks
Nagarajan G
Once again, thank you very much for answering and for your time and effort!
Your solution is very interesting, although it is over my knowledge. I will review it in detail tomorrow.
By now I have briefly tried to execute it. It is works, but I do not get where are resulting log files.
I've did commented the 'rm ..' command, but those /tmp/ file are pipes (that I do not understand well, but tomorrow..) and after process is done they are 0-size.
I also have get something to work, but my code is far bigger and I did not take care the error-stream.
I've prepared a peace of code that should be added to the beginning of a script.
One benefit, it seems, it has (if I did not mis-understand your code completely,) that it does not require a script to reach the end. The script could exit in the meddle or could be killed or stopped by any other way.
This is what I have:
I will appreciate your oppinion and advice regarding that.
Alex
Hi Guys,
I want to redirect the output of 3 scripts to a file and then mail the output of those three scripts.
I used below but it is not working:
OFILE=/home/home1/report1
echo "report1 details" > $OFILE
=/home/home1/1.sh > $OFILE
echo... (7 Replies)
hi,
i am using ftp to get files from remote server. inside the ftp i want to us ls -ltr command and send the output of it to a file.
ftp -n remote_server <<_FTP
quote USER username
quote PASS password
prompt noprompt
pwd
ls -ltr
get s1.txt
bye
_FTP
i... (4 Replies)
hi,
i have a html form which call a perl program, this perl program calls a shell script.
<html>
<head>
<title>demo</title>
</head>
<body>
<form name="frm1" action="/cgi-bin/perl_script.pl" method="post">
<input type="text" name="fname">
... (1 Reply)
Below script perfectly works, giving below mail output. BUT, I want to make the script mail only if there are any D-Defined/T-Transition/B-Broken State WPARs and also to copy the output generated during monitoring to a temporary log file, which gets cleaned up every week. Need suggestions.
... (4 Replies)
Hi, I put a for loop in a script to eject backup tapes from the robot. The command echo' output goes to the log file without problem, but command vmchange's output does not go to the log file although it's working fine. It still displays on the screen. I've tried '2>&1 1>$log', but nothing changed.... (5 Replies)
I've been using tftp in one of my file
#!/bin/bash
filename1="config1h.txt"
filename2="config15.txt"
hostname="test.com"
tftp $hostname <</dev/null
get $filename1
get $filename2
quit
EOF
My output looks like this
# ./test3.sh
tftp> Received 1262 bytes in 0.0 seconds
tftp> Received... (2 Replies)
Dear All:
I am trying to do something that (I thought) was relatively straightforward, but my code snippet does not seem to work.
Any suggestions?
Thank you
Sincerely yours
Misha Koshelev
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include... (0 Replies)
Hi,
I have a process running in the background, which throws up some output to the terminal when I run my script. How can I read this output from my script?
Thank you. (5 Replies)
hi,
i wat to get the output of a grep command in a file. but when i am trying out the same grep command in the unix prompt its working fine.. i am getting the output properly.. but when i am writing the same command inside my shell script , its just creating a new output file with no contents... (11 Replies)
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)