LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 04-15-2008, 01:52 PM   #1
prodsac
LQ Newbie
 
Registered: Apr 2008
Location: Montreal
Distribution: Ubuntu, Suse, Solaris
Posts: 1

Rep: Reputation: 0
how to log everything from a bash script to a file


Hi, I have a menu that support techs will use to start-stop applications, get infos on servers, etc.

I would want to be able to trace everything they do with it.

here would be the bash script:

#################################################################
#!/bin/bash
let "loop=0"
while test $loop == 0
do
clear
echo "Intranet2008"
echo "--------------------------------------------------------------"
echo "a. PROD"
echo "b. PRP"
echo "c. Test"
echo "d. Dev"
echo "--------------------------------------------------------------"
echo "q. Retour au Menu"
echo "Choix?"
read choice

case $choice in q)
let "loop=1"
esac

case $choice in a)
echo "Connexion a PROD"
sh menu-intranet2008-prod.txt
esac

case $choice in b)
echo "Connexion a PRP"
sh menu-intranet2008-prp.txt
esac

case $choice in c)
echo "Connexion a TST"
sh menu-intranet2008-tst.txt
esac

case $choice in d)
echo "Connexion a Dev"
sh menu-intranet2008-dev.txt
esac


done
#################################################################

Do you have an suggestion?

thanks,

Marc
 
Old 04-15-2008, 02:11 PM   #2
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,132

Rep: Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456Reputation: 2456
Well, a very quick-and-dirty solution would be to put another echo statement, after the one you already have, like this:

echo "User did this.. at `date`" >> $HOME/shell-script-log-file

This would burp out everything that particular user did, to a log file in their home directory, appending as it went, and putting a date-time stamp on each command.
 
Old 04-15-2008, 04:56 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,944
Blog Entries: 54

Rep: Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731Reputation: 2731
...and another way could be to use functions plus "logger". With logger you can output to script or syslog. I've taken the liberty to restructure your script a bit. This is easier on the eyes and I hope easier to use and understand or so I hope:
Code:
#!/bin/bash
log() { logger -t scriptname "$@"; echo "$@"; }
display() { echo "Intranet2008, choisir un uhh, choix:"
 select choice in PROD PRP TST Dev Menu; do
 case "$choice" in
  PROD) log "Connexion a PROD"; sh menu-intranet2008-prod.txt;;
  PRP) log "Connexion a PRP"; sh menu-intranet2008-prp.txt;;
  TST) log "Connexion a TST"; sh menu-intranet2008-tst.txt;;
  Dev) log "Connexion a Dev"; sh menu-intranet2008-dev.txt;;
  Menu|*) clear; display;;
 esac; done
} # end display
display
exit 0
 
  


Reply


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
Bash script to put log files into single file and email DragonM15 Programming 13 11-08-2007 03:27 AM
bash script help - finding last n log files in all sub folders jeepescu Programming 4 11-03-2007 07:57 PM
Clean log bash script? QuarQuar Linux - General 4 10-27-2007 11:46 PM
Bash script for server log (namely var/log/messages) tenaciousbob Programming 17 05-24-2007 10:43 AM
Where is the bash log file? alaios Linux - General 5 04-28-2006 03:28 AM


All times are GMT -5. The time now is 12:44 AM.

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