Linux - ServerThis 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.
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.
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.
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.
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.
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.
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?
#/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.
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.
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 ~]#
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.