Each time a script is called. A log file is created with time and date + Bash Script.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Each time a script is called. A log file is created with time and date + Bash Script.
Wrote a Script to kill (with all zombie process) and start asterisk where users having issue with the service could use a button on a certain webpage to restart asterisk. Am cool with it and am not having any issue with..What i would really like to do now is,.each time someone will use that button to restart the service a log should be created with time and date.
If reading correct you allready have script that restarts asterix. Why not write the log there? Or you could use the script of asterix itselfs to do the logging.
What language is your script in?
The start-stop script should be plain bash and should easily be modified.
If reading correct you allready have script that restarts asterix. Why not write the log there? Or you could use the script of asterix itselfs to do the logging.
What language is your script in?
The start-stop script should be plain bash and should easily be modified.
Sorry for the late reply zhjim,
Am actually using simple bash to write. Well giving more details is that i got 2 script, one to kill asterisk and another to start. U must be thinking why i got 2 script when i can do both actions in only one script. Well i tried but when i ran the script it only killed asterisk. It won't start. So what happens now is that when someone uses the button on the web page. it first calls the kill-asterisk script then start-asterisk script. And this does work!
You could call the start asterix script a the end of the stop script.
As a reference how to do both in one script check out the scripts in /etc/init.d. They are called something like this
Code:
Usege: prog_name start | stop | restart
(Dunno if you are familary with this form of notation. | pipesymbol means or. So you can call the program like prog_name start or prog_name stop or prog_name restart.)
Heres a example script.
Code:
function start_asterix {
your way of starting asterix
if [ $? -eq 0 ]; then
echo date 'asterix started' >> a_log_file
fi
}
function stop_asterix{
your way of stoping asterix
if [ $? -eq 0 ]; then
echo date 'asterix stopped' >> a_log_file
fi
}
case "$ACTION" in
start) start_axterix
;;
stop) stop_asterix
;;
restart) stop_asterix
start_asterix
;;
*) echo "Usage $0 start | stop | restart"
esac
function start_asterix {
your way of starting asterix
if [ $? -eq 0 ]; then
echo $(date) 'asterix started' >> a_log_file
fi
}
function stop_asterix{
your way of stoping asterix
if [ $? -eq 0 ]; then
echo $(date) 'asterix stopped' >> a_log_file
fi
}
Otherwise, looks like exactly what the doctor ordered.
Besides using a dedicated logfile at this stage, it could also be generated as an entry in the system syslog facility and handled later on by syslog-ng or alike to split it again to different logfiles or forward it to a remote syslog server:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.