LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-28-2011, 11:03 AM   #1
mtm100
LQ Newbie
 
Registered: Oct 2011
Posts: 6

Rep: Reputation: Disabled
Bash- Some Simple Code on how to log events and handle errors


Hi,
Being new I am wriiting a simple bash script.

I need to log events from within a bash script to a .txt file. Also will include some simple error handling, including logging that to the log file.

Anybody got a few simple lines of code that would accomplish this? Probably very basic question!

Thanks
 
Old 10-28-2011, 11:28 AM   #2
SecretCode
Member
 
Registered: Apr 2011
Location: UK
Distribution: Kubuntu 11.10
Posts: 562

Rep: Reputation: 102Reputation: 102
Code:
echo "Your message" >> yourlog.txt
will do what you've specifically asked for (make sure to use >> to append to the file, instead of overwriting it).

But if you want to do event logging "properly" take a look at syslog. man syslog and, from bash, man logger. Then you can google for examples!
 
Old 10-28-2011, 01:22 PM   #3
mtm100
LQ Newbie
 
Registered: Oct 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thanks Secretcode,
Are there any other snippets that would be useful in trapping the errors like On Error or Error Level which you can trap and then decide what to do with like with an If statement? Then use your code to append to the log file?
Thanks
 
Old 10-28-2011, 01:41 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,564

Rep: Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901Reputation: 2901
Have a look at 'help trap'.
 
  


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) Redirect all output from script to all.log and copy of errors to err.log hmsdefender Programming 5 03-05-2010 02:52 PM
Bash script can't handle errors when run by cron rosv Programming 4 01-08-2009 08:50 PM
Help. New to Linux. Simple Code. Many Errors. jat12 Programming 7 11-24-2007 03:02 AM
errors with simple C++ Code... openGL problem? poeta_boy Programming 4 11-08-2004 01:34 PM
G++ - why am i getting errors compiling this simple code leroy27336 Programming 4 11-18-2003 09:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:23 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration