When logged in as ‘chuck’ I can # cd / to get to my root directory. Next I can run an rsync command to backup files.
When I try to set the same thing up as a cron job under root, my files are not being backed up. I believe it is because the starting directory location is wrong.
So, when executing a script or a command under cron as root, how do you specify the directory statement so it starts in the same spot as if you are logged in as a user and do a **#cd **/ command?
Yes, you can tell I’m a newbie and not familiar with how the linux directory structure works…thanks…
So…just to make sure I understand: if I am logged in as root and I do a cd / then that gets me to the same starting directory as if I were logged in as chuck and I do a cd / (?)
Exactly. To go along with this there are two options when changing
directories… absolute paths and relative paths. Relative paths depend
on where you are currently and absolute paths depend nothing. Having
fewer dependencies typically makes your code run more-smoothly.
cd /
That is an absolute path because it starts with ‘/’. There is only one
‘/’ and since you start there anything you put after it (including
nothing) still is an absolute path. A few relative path examples:
cd ./
cd ./let/us/change/to/here
cd let/us/change/to/here
cd …/…/couple/levels/up/then/here
These all depend on you knowing where you start. That’s fine as long as
you do, but I always try to start knowing where I start with an absolute
path because it reduces problems significantly.
In your case no matter who runs cd / they should get to the root of the
filesystem and, as ken yap mentioned, if they cannot then you have much
bigger problems.
Good luck.
ken yap wrote:
> When you do a cd / your current directory becomes / no matter who you
> are, even the pope.
>
> (Well, permissions permitting, but a system where you couldn’t cd to /
> would be unusable.)
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org