Linux - NewbieThis 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
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.
in this directory,/var/spool/cron/crontabs, there are 2 files; 1 is named as the username (penguen1) and the other is "root". i have tried it on both, what is wrong with what i am trying to do it everyday?
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.XXXXcRiecM installed on Wed Aug 6 16:05:06 2008)
# (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
21 13 * * * root cd /home/penguen1/Desktop/oto tar -cvf f.tar /home/penguen1/yedekleme/rdiff
must i use any punctiations like ";" between different commands? i tried ":" after oto (the directory to backup using tar), it didn't work as well
please help
What would the format be if i tried to do it by placing under /etc/cron.daily ?
hi thank u all. I have tried what is in the first reply but didn't work. This is a linux distro: pardus. I also tried it without the "root" user, result: same. So i will try to make it with a script as you told me to billymayday. But i don't know if it's ok if i just make a text file and change the file's name to make it smthing.sh . I will to try to make it this way until you reply. I will also try copying a .sh file and changing its content.
BTW i forgot to state in my first post that i tried it by using crontab -e before what i told i tried here.
Here is what i did;
at /home/penguen1 right click on white space > new > text file
and here is what i wrote in it;
#!/bin/bash
cd /home/penguen1/Desktop/oto
tar -cvf fdfdfd.tar /home/penguen1/yedekleme/rdiff
i changed the name of the file to sdf.sh
Then on the command line (yakuake for pardus) (btw do i need to become root to set the cron job?)
>crobtab -e
39 16 * * * /home/penguen1/sdf.sh
then ctrl+x and "y" and "enter"
it says installing new crontab
but the cronjob still doesn't work although when i double click on the sdf.sh it does do the job.
what can i do?
One last thing; i must stop the mysql server and restart it after the tar job. is it okay if i add the "service mysql_server stop" to the top afer the bin/bash and "service mysql_server start" to the end of the script (sdf.sh) Will there be enough time for mysql_server to stop before tar backups? because it takes like 3 seconds for mysql_server to stop
One more last thing: i should add someting (preferably date) to the end of the backup file name (sdf+smth.sh) so that the previous backup is not deleted each time. How can i do it?
Stopping/starting services can only be done by root. If you add the mysql lines, you should put the script in root's crontab, not penguen1's (ie first change to root, then crontab -e and don't forget to remove it from penguen1's crontab). If you leave out the mysql lines, you can probably run it as penguen1 and therefore leave it in penguen1's crontab.
Note that it can take a minute for cron to see the changes you make. How did you tell if the job worked or not (either manually or from cron)? I also wonder what you're trying to tar that requires stopping mysql first? Your database itself? Perhaps a mysqldump is suitable?
Scripts are text files with commands in them. They require a specific syntax, depending on the scripting language (Bash, sh, ksh, Tcl, Perl, Python,...). They also need an interpreter program, like /bin/bash for Bash-style scripts, which is put at the top in the shebang (#!) line. If no shebang line is put in, the current shell of the user that runs the script is used (ie the shell you're working in). Your "default" or login shell is stored in /etc/passwd and can be changed with the "chsh" (CHange login SHell) command.
As for the time required to stop mysql: this depends if you run the "service mysql stop" command in background or not.
If in the background (ie "service mysql stop &"), the cd and tar commands are started without waiting for the stop of mysql to complete. If not in the background ("service mysql stop" without ampersand), then the script will wait with the "cd" command until the mysql has stopped.
To add the data, use something like:
Code:
today=`date +%Y%m%d`; tar -cvf fdfdfd_${today}.tar /home/penguen1/yedekleme/rdiff
I suggest you read up on Bash, in particular the use of quoting and on job management.
"yes i am trying to backup a mysql db. I tried to use mysqldump but it says command not found when i try to use it.
i also tried mysqlhotcopy and do not remember what error came up. I can not try anything during the work hours here, i can try only after 18:00 here. (At the time of post it is 13:10 here)So i can not remember now the error.
I did learn mysqldump is better but the pc i must do the auto backup has fedora core 4 on it and it is harder for me to understand anything about it. So i don't know what to do when it says command not found after typing mysqldump and enter.
if stopping and starting the mysql_server job must be done by the root user, and if i just want to use the .sh file until i am able to do it with cron, is there anything i can add to the script to switch to root? How can i do it with the root with the cron?
as sa * * * root commands. is enough?
must i put the password as well? how?
I would really appriciate it if u helped me do this, i am new to linux and still the boss expects me to achieve auto backup right off. This is my 3rd thread here, but evertime i learn smth to do, a new problem comes up, so i still haven't been able to make it happen.
I think i will try to do it with the tar + cron for now since i have no idea how to fix mysqldump- mysqlhotcopy errors. My final position is;
when i double click on the sdf.sh file which has
"
#!/bin/bash
today=`date +%Y%m%d`
cd /home/penguen1/Desktop/oto
tar -cvf sdf_${today}.tar /home/penguen1/yedekleme/rdiff
"
in it, it does make a tarball(if this is what it is called) in the dest. folder with the date of the day attached to "sdf_".
but when i add a cronjob with "crontab -e" using the line;
09 11 * * * /home/penguen1/sdf.sh
nothing happens. Is this time stated here same with what is written on the taskbar clock?
If you ask a lot of questions, you should number them to make answering easier.
1. mysqldump gives you "command not found" issue
Have you specified the correct path? If you don't give a path (ie just type "mysqldump"), then Linux will search all directories in $PATH (do a "echo $PATH" to see them). If it doesn't find the command in any of those directories, you get the message "command not found". If you installed mysql as rpm package, you can use a command like "rpm -q --filesbypkg mysql" to find where it's installed.
2. Don't bother about the time. People contribute voluntarily to this forum, whenever *they* have time. So don't expect to see a response when it's convenient for you.
3. To run the job as root, there are a few approaches:
-switch to root, then do "crontab -e" to put the job in root's crontab settings
-configure "sudo" to make penguen1 able to run the job as if he was root
-change the ownership of the .sh file to "root" and then set the special setUID permission
I recommend sticking to the first option since you're new to Linux.
Adding to root's crontab is similar as for the other users:
Code:
#switch to root - it'll ask for the password
su -
#edit root's crontab
crontab -e
#now add the cron job, same format as usual, ie
39 16 * * * /home/penguen1/sdf.sh
#exit the editor and save the changes you made, then check if it worked
4. Please read billymayday's post: you should give full path's to the commands used in the .sh file. Not just "tar" and "date", but "/bin/tar" and "/bin/date". This is because cron jobs run in their own special environment, which is different from penguen1's standard environment.
5. As I told you in my earlier post, you should allow cron a little time to ingest the changed settings. So don't put the system time (from the taskbar clock) into the crontab settings. Rather, use a time that's still a few minutes away.
ie if it's now 16h, use something like 05 16 * * * /your/job
Alternatively, for testing only, you could have cron run the job each minute, ie:
* 16 * * * /your/job
I have been able to do it, and would like to post it so that others may benefit.
i created a .sh file by creating a text file and changing its name to something.sh with;
#!/bin/bash
today=`date +%Y%m%d`
cd /home/penguen1/Desktop/oto
tar -cvf sdf_${today}.tar /home/penguen1/yedekleme/rdiff
in it and placed it under cron.daily folder can not remember where the folder is now. I don't know now but i could not do it using crontab -e. I made the file something like executable by right clicking on it and putting a check(can't remember what it wrote there) so that it would work when you double click on it.
It does really take about two minutes cron to find out about the job. So try a few minutes after the clock on the taskbar when you testing.
I adjusted the time of the cron.daily jobs from the crond file in the same folder with the job folders (cron.daily,cron.weekly,...) by opening it with a text editor.
thank you all
If user's crontab settings (crontab -e) are not working, it may be useful to check out
/etc/cron.allow (list of users that are allowed to use cron) and/or /etc/cron.deny files. Same goes for the
status of the cron service, as in geniushasan's post.
The cron.daily,... folders are usually in /etc/ or in /etc/cron.d/.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.