■ Requirement : redirect output of script to a file(Need to save log in a file and file should be mentioned in the script itself)
■ OS Environment : Linux[RHEL, Centos]
■ Application: bash
■ Implementation Steps :
1. Create a bash script.
2. add following line :
exec > >(tee /var/log/my_logfile.txt)
Example :
$ cat /etc/init.d/crond |head -5
#! /bin/bash -x
exec > >(tee /var/log/my_cron_logfile.txt)
$ service crond restart
$ cat /var/log/my_cron_logfile.txt
Starting crond: [ OK ]
■ OS Environment : Linux[RHEL, Centos]
■ Application: bash
■ Implementation Steps :
1. Create a bash script.
2. add following line :
exec > >(tee /var/log/my_logfile.txt)
Example :
$ cat /etc/init.d/crond |head -5
#! /bin/bash -x
exec > >(tee /var/log/my_cron_logfile.txt)
$ service crond restart
$ cat /var/log/my_cron_logfile.txt
Starting crond: [ OK ]
No comments:
Post a Comment