Linux - Server This forum is for the discussion of Linux Software used in a server related context. |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
|
05-07-2011, 05:13 AM
|
#1
|
Member
Registered: Feb 2011
Posts: 179
Rep:
|
How to create log file in shell script
Hi all,
I tried to create logfile for the below shell program but i was not able to get log file,can anyone help me for the below program to create a log file for the shellscript.
#/bin/bash
mount -t cifs -o user="$1",password="$2" "$3"/"$1" "$4"
echo " Mounted Successfull " >> /var/log/kannan
cd "$4""$5"
date=`/bin/date "+%Y.%m.%d.%H.%M.%S"`
mysqldump -u"$6" -p"$7" "$8" > $date.sql
echo " Backup taken Successfull " >> /var/log/kannan
rm -rf $date.sql
Thanks,
Last edited by ramecare; 05-07-2011 at 05:15 AM.
|
|
|
05-07-2011, 05:28 AM
|
#2
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
if you have permissions to /var/log as the executing user then that will work just fine. You might also like to use the "logger" tool to send messages into syslog more nicely.
|
|
|
05-07-2011, 05:28 AM
|
#3
|
LQ Guru
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
|
Hello,
Have a look at the /var/log directory and which user runs your script. That might shed some light on why the log doesn't get created. Also you're writing to the log that your processes have completed successfully, even when they might fail so there's no real use since you cannot confide in the log file. You should put some test in place to check if the commands exited with a success code and change the message accordingly.
Kind regards,
Eric
|
|
1 members found this post helpful.
|
05-07-2011, 05:46 AM
|
#4
|
Member
Registered: Feb 2011
Posts: 179
Original Poster
Rep:
|
Iam running the program from root user only,i have given permission for tat /var/log and i have given full permission for the logfile kannan,but also i was not able to get the logfile,can anyone give suggesion on this.
Thanks,
|
|
|
05-07-2011, 06:13 AM
|
#5
|
LQ Guru
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
|
Hello,
If your script runs as root than it should work. Also if running as root then what's the need of setting the permissions to kannan? Try running in a terminal:
Code:
echo "test">>/var/log/kannan
and see if the file gets created and that it has the word test in it.
How does your script run? From a crontab? Or do you only launch it manually?
Kind regards,
Eric
|
|
|
05-07-2011, 07:13 AM
|
#6
|
Member
Registered: Feb 2011
Posts: 179
Original Poster
Rep:
|
#/bin/bash
mount -t cifs -o user="$1",password="$2" "$3"/"$1" "$4"
echo "test">>/var/log/kannan
cd "$4""$5"
date=`/bin/date "+%Y.%m.%d.%H.%M.%S"`
mysqldump -u"$6" -p"$7" "$8" > $date.sql
tar -zcvf $date.sql.tgz $date.sql
rm -rf $date.sql
When is run echo "test">>/var/log/kannan this alone in its working but when i user this command echo "test">>/var/log/kannan with my shell program i was not able to get log file,could any one help me wat whould be the problem,iam running my shell program manually only.
Thanks,
|
|
|
05-07-2011, 07:15 AM
|
#7
|
LQ Guru
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
|
Hi,
Do the other commands in your script execute as expected?
Kind regards,
Eric
|
|
|
05-07-2011, 07:29 AM
|
#8
|
Member
Registered: Feb 2011
Posts: 179
Original Poster
Rep:
|
Yes other commands works in the shell script except echo "test">>/var/log/kannan, any idea about it,can any one help me on this.
Thanks,
|
|
|
05-07-2011, 07:35 AM
|
#9
|
LQ Guru
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
|
Hi,
Try using echo from within the script but without redirection, that is only:
Code:
echo "checking echo command"
I thought that it might be a path problem and was going to advice to use full paths but normally the echo command and the mount command are in the same directory (/bin) so that should be OK. Check just to make sure with:
Code:
which echo
which mount
in a terminal to verify that they are in the same path. If the mount command is working, then so should the echo command.
Kind regards,
Eric
|
|
|
05-07-2011, 07:44 AM
|
#10
|
Member
Registered: Feb 2011
Posts: 179
Original Poster
Rep:
|
This was the command iam running ./newshell ramkannan Linux123@ //10.200.1.125 /MT /test root ecare2@ employeedb
#/bin/bash
mount -t cifs -o user="$1",password="$2" "$3"/"$1" "$4"
echo "test"
cd "$4""$5"
date=`/bin/date "+%Y.%m.%d.%H.%M.%S"`
mysqldump -u"$6" -p"$7" "$8" > $date.sql
tar -zcvf $date.sql.tgz $date.sql
rm -rf $date.sql
As u told i used this echo "test" command in the program, but i could not get the echo output but other all the the output iam getting,any idea wat would be the problem.
[root@itsupport ~]# which echo
/bin/echo
[root@itsupport ~]# which mount
/bin/mount
[root@itsupport ~]#
Thanks
Last edited by ramecare; 05-07-2011 at 07:46 AM.
|
|
|
05-07-2011, 07:57 AM
|
#11
|
LQ Guru
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
|
Hi,
Just looking at your posts again I noticed this:
Is that a typo? It should be
Change it if it's a typo and try again.
Kind regards,
Eric
|
|
|
05-07-2011, 08:51 AM
|
#12
|
Member
Registered: Feb 2011
Posts: 179
Original Poster
Rep:
|
It's working now,Thank u very much
|
|
|
05-07-2011, 08:54 AM
|
#13
|
LQ Guru
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
|
Hi,
Great to hear you've got it fixed. Sorry I didn't notice before what was missing. Have fun with Linux.
Kind regards,
Eric
|
|
|
All times are GMT -5. The time now is 01:42 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|