LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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,436
Blog Entries: 11

Rep: Reputation: 181Reputation: 181
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,436
Blog Entries: 11

Rep: Reputation: 181Reputation: 181
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,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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 11.4
Posts: 1,319

Rep: Reputation: 252Reputation: 252Reputation: 252
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,436
Blog Entries: 11

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


Reply

Tags
bash scripting, log


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 12 01-19-2013 09:37 AM
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


All times are GMT -5. The time now is 09:57 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration