Reputation: 4533
I have written one script which is working fine when I execute it by ./script.sh
.
Script path: /var/script.sh
.
I need to do some action in /var/project
. For that, I have written this script.
cd /
cd /var/project
echo "In folder..."
Now I need to run this file using sudo crontab -e
.
Crontab -e code:
@reboot /var/script
I have also echo
some message and it prints fine. But as in my above code,
it is not going to my path. It goes to this path.
/home/myuser
Instead of that path I need to go
/var/project
Thanks for the help. :)
Upvotes: 0
Views: 30
Reputation: 715
Root will use /home
because it's default path of root.
Give you default path before script executes.
add this code at top of the script.
cd /
cd /var
Now it'll use you path.
Upvotes: 1