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.
I am trying to figure out how to write a cron job to put the current date into the name of a new directory that the cron job is going to create on my local box.
The 100104 would be the current date each day. I have not been able to figure out what command to use to get the current date from my box, so I can't figure out how to do that part of this cron job. I just figured out how to write a cron job today without asking for any help up to this point.
Will some one tell me what command will get the date and point me to some good information that will show me how to use it in my cron job or tell me a better way to do what I am trying to do?
of course this isn't a final version of your backup script, but it should get you started, i can see you know how to reference help given your progress to this point.
should do it. For simplicity, you might want to put both commands into a shell script, and then have cron invoke that. And for your first cron command, unless you want it run every minute during the 4 AM hour, replace the first asterisk (before the 4) with a 0 (or whatever minute you want it to run at).
The directory was created like this - "serverbackup$(date" on the first pass
Then the second pass created another directory like this "+%m_%d_%y" inside "serverbackup$(date"
The files that were in serverbackup were moved to "serverbackup$(date"
I tried it by taking out the space between "date" and "+" so it looked like this $(date+%m_%d_%y) that created this "serverbackup$(date+%m_%d_%y)" then the files were moved into that directory and the second directory was not created. Doing this $(date+%m%d%y) did the same thing as the other.
Thanks for pointing out my mistake with the minute value.
I don't understand how to know or control what shell is being used.
I assume I am using the BASH shell. I start konsole in KDE and whatever shell is automatically started with that is what I am using. The man page for BASH is major information overload and very confusing. Google brings up sites that basically have the same information. I have not been able to find a tutorial that explains what the information in the BASH manual is saying. I will figure this out one way or another, sooner or later. This whole learning process with Linux has been very difficult but I won't stop because I like what I see and have learned so far. It sure beats using mswindows.
tells which ever shell that is handling this script that it need to be run with the said interperter (/bin/bash in this case). So it will invoke bash and pass it the script.
let's start with the basics - run the following:
/bin/bash --version
FYI-
i have 2.05b, and verified the mkdir command in the code i suggested.
to do so, i created the file 'bak' in my home directory which now contains the codeblock below. It (today) makes the directory backup10_02_04 when i run './bak' from my home directory.
Thanks to all for trying to help. I am no closer to understanding this or getting it to work. The more I read to get my questions answered the more questions I have. I don't know how to make this work in the crontab. I can make it all work perfectly if I type it in at the prompt. I also have no idea how to make the crontab execute the commands from another file either. There is clearly something missing from my knowledge and understanding but I don't know what. At this point I am totally confused.
What that was suggested here is that you put the commands in a file, we call that a script, make it executable and make cron execute that instead of having to have all the commands in the crontab.
The script is just a plain text file, but you'll have to make it executable by doing a chmod.
In the crontab, you replace your original commands with the script you have just wrote.
for example if the script you have created is myscript, you have this in your cron tab.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.