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.
how does that cause a problem? it is ran all at once. the date will not change that fast.
Theoretically it COULD change that fast, in practical terms it's unlikely. But why take the risk for the sake of a bit of good scripting that also reduces the number of external program calls. Your choice though. I know what I do in my production scripts.
Theoretically it COULD change that fast, in practical terms it's unlikely. But why take the risk for the sake of a bit of good scripting that also reduces the number of external program calls. Your choice though. I know what I do in my production scripts.
ok if it is done at 0000 then a second goes by then the date will change, then an if statemnt will have to be added to check that. then more coding will be needed, yes.
ok if it is done at 0000 then a second goes by then the date will change, then an if statemnt will have to be added to check that. then more coding will be needed, yes.
An if statement that can TOTALLY be avoided by assigning the current date that the script was initiated at as a variable at the start. Oh wait, that's what I did!
Last edited by TenTenths; 12-12-2016 at 10:07 AM.
Reason: ;) To show that I'm amused by this now.
An if statement that can TOTALLY be avoided by assigning the current date that the script was initiated at as a variable at the start. Oh wait, that's what I did!
Thank you, thank you, thank you, you've made me the happiest admin in the world
Quote:
Originally Posted by BW-userx
you were thinking eggs, while I was thinking toast.
Problem solved. lets move on..
I just happened to have been doing a LOT of this kind of scripting recently so when it was clear that the OP needed specific scripting examples I was pretty much there.
@TenTenths...... I tried to use your code mentioned above but there seems to be a problem with your code in the line where 'mkdir' starts. I even navigated to the folder where the directory is being created and still got an error
I could've sworn I have seen a command that uses -1, meaning less than a day old to use to copy the file into a directory less than a day old but I don't remember it
@TenTenths...... I tried to use your code mentioned above but there seems to be a problem with your code in the line where 'mkdir' starts. I even navigated to the folder where the directory is being created and still got an error
are you one the system side? if yes, then give it root permissions?
where is the bash file being run?
if on the user side trying to do stuff on the system side. root permissions needed.
if you dump it in your cron.daily it should work without sudo before the mkdir.
if you need to give it sudo permissons, then give the 'user'/owner of that file sudo passwd none in your sudoers file to get past having to enter a password each time it is ran.
Code:
!#/bin/bash
sudo mkdir /somewhere on the system side/
In addition to the good advice from BW-userx, if you're calling things from the cron then you may need to specify the full paths to things like mkdir and date. For example in CentOS:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.