Answer the question
In order to leave comments, you need to log in
How to execute a script in the same place where it is located?
I do through the task scheduler (crontab) the launch of the script when it is turned on. the script is located in /home/andrey/mine/Vanila/bar/start.sh. When executing, I noticed that it does all operations with files in home / andrey. I can not understand how to tell him to execute the program in the same place where the script is located.
Answer the question
In order to leave comments, you need to log in
as an option: all actions with the files participating in the script should be carried out using absolute, not relative paths:
# cp file.txt /mnt
cp /home/andrey/mine/Vanila/bar/file.txt /mnt
The simplest is to combine two commands and write in the cron line: cd /home/andrey/mine/Vanila/bar/ && /home/andrey/mine/Vanila/bar/start.sh
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
there $DIR
will be a folder where the script file is located. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question