LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-14-2012, 05:05 AM   #1
y0_gesh
LQ Newbie
 
Registered: Nov 2011
Posts: 11

Rep: Reputation: Disabled
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.

Anyone got an idea how to make this work ?
 
Old 08-14-2012, 05:33 AM   #2
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
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.
 
Old 08-16-2012, 02:28 AM   #3
y0_gesh
LQ Newbie
 
Registered: Nov 2011
Posts: 11

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by zhjim View Post
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!
 
Old 08-16-2012, 06:32 AM   #4
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
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
 
Old 08-16-2012, 03:11 PM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
I think that should really be:
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
}
Otherwise, looks like exactly what the doctor ordered.

--- rod.
 
Old 08-16-2012, 04:11 PM   #6
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
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:
Code:
$ logger -t asterix -p daemon.info started
$ logger -t asterix -p daemon.info stopped
to generate:
Code:
Aug 16 23:00:59 the_hostname asterix: started
Aug 16 23:07:33 the_hostname asterix: stopped
 
Old 08-17-2012, 03:16 AM   #7
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
You're totaly right Nbomer.
Nice stuff as well Reuti.
 
  


Reply

Tags
bash scripting, log



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Get file modification date/time in Bash script cmfarley19 Programming 16 04-15-2015 06:25 PM
Script - Find time between entries in log file blsimpson Linux - Newbie 16 07-24-2012 06:03 PM
Need help to have a rsync script log output to a file with time stamp Thaidog Programming 5 11-15-2011 05:37 PM
[SOLVED] how do i log the start/completion (time&date) of my cron job script? davide123 Linux - Newbie 3 01-11-2010 06:25 PM
bash script for displaying a file one line at a time. panchosansa Programming 6 10-12-2006 10:54 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration