Linux / UNIX Tech Support Forum
This is a discussion on shell script output to log file in /var/log/ within the Shell scripting forums, part of the Development/Scripting category; Hi. I've created a script e.g., #!/bin/bash echo "test" script name is "test12.sh" How can i redirect its output to ...
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi.
I've created a script e.g., #!/bin/bash echo "test" script name is "test12.sh" How can i redirect its output to /var/log/test12.log file and also on screen? Can i anyone help me please. Regards Asim |
| Sponsored Links | ||
|
|
|
||||
|
Try something as follows:
Code:
#!/bin/bash
LOGFILE=/var/log/test12.log
log(){
message="$@"
echo $message
echo $message >>$LOGFILE
}
log "This is a test!"
__________________
Vivek Gite Linux Evangelist |
|
|||
|
Dear
Thanks for your reply. Actually i've a file called script.sh I want to log its error and output into /var/log/test12.log file, same like other program logs are logged into /var/log/message email log in /var/log/maillog with hostname username and date/time etc. Can you please let me know how can i do this? |
|
||||
|
Above script does the same. Otherwise use logger command:
__________________
Vivek Gite Linux Evangelist |
|
|||
|
Dear
I've tried it and it works but i've to create another file. e.g., Code:
#!/bin/bash
LOGFILE=test12.log
q=`/path/to/script.sh`
log(){
echo "$(date +%c) $*" >>$LOGFILE
}
log "$q"
Last edited by nixcraft; 05-13-2009 at 04:02 PM. |
|
||||
|
A better approach may be
HTML Code:
/path/to/script.sh > /path/to/log.file
__________________
Vivek Gite Linux Evangelist |
![]() |
| Tags |
| linux , log a message , logger , shell script log file , shell scripting , unix |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Solved] Shell script for ftp the file | vishal_titre | Shell scripting | 4 | 08-21-2009 03:50 PM |
| How to Redirect OutPut of Shell Command to a text file | Hadi | Shell scripting | 1 | 04-29-2009 07:27 PM |
| Shell Script To Outputs File Permissions of Most Recently Modified File | glen_4455 | Shell scripting | 1 | 08-25-2008 02:39 PM |
| shell script to search specific file from txt file inside zip file and extract it | aasif.shaikh | Shell scripting | 2 | 05-31-2008 06:44 PM |
| error shell script no such file or directory /bin/sh | Linux software | 1 | 01-08-2006 08:34 PM | |