I have my script in /home/testing/program
. My script name is test.sh
. I want to run my script from other directory. I changed the permissions of the file. In my script I have redirected the output to some(output-test.sh
) file. I need to run all my script from other directory. If i run the script in the current directory it works fine. Please help me to do this. Thanks in advance.
Asked
Active
Viewed 799 times
-1

disha
- 51
- 1
- 8
-
Can u give me the answer...please – disha Feb 08 '19 at 05:55
-
I am trying to execute my script from other directory for past two days...can u please help me... – disha Feb 08 '19 at 05:57
-
`some commands | mail -s "output" "abc@gmail.com"` – Cyrus Feb 08 '19 at 06:19
-
Actually my test.sh script runs fine...But am getting permission denied error for output-test.sh....Please help me to solve this error – disha Feb 08 '19 at 06:22
-
@Cyrus Thank u soo much its works!!!!!!!!!! – disha Feb 08 '19 at 06:57
-
sir...But when i run this in cron job as * * * * * sh/home/program/testing /test.sh ...am not getting the email body – disha Feb 08 '19 at 07:44
-
@cyrus is there any other way to overcome permission denied error when i run the script outside my directory – disha Feb 08 '19 at 08:32
1 Answers
0
In Unix systems, absolute paths start with / . So you can use absolute path to run a script. In your case all you have to do is run this command from the terminal
sh /home/testing/program/test.sh
. It does not matter from which directory you run the command from until you use the absolute path of the script.
Also the file in which the output is written should be defined with absolute path in script file. For example, in your case
/home/centos/rr/email-body.txt
so that the file is recognized by the OS even when the script is executed from the other directory or from any directory whatsoever.

daedalus_hamlet
- 208
- 1
- 2
- 8
-
In my test.sh file i have redirected the output to output-test.sh. If i run sh /home/testing/program/test.sh ... the test.sh is running fine and am getting permission denied error for output-test .... I am using Linux – disha Feb 08 '19 at 06:00
-
If you are comfortable with sharing the script here,do so. It helps us to help you better ! – daedalus_hamlet Feb 08 '19 at 06:02
-
-
-
post your test.sh script. It consists of the code to execute the output-test.sh . Maybe that is where the problem lies. – daedalus_hamlet Feb 08 '19 at 06:27
-
-
-
The output of some commands will be stored in output-test,sh...And the body of the mail will be the contents of output-test.sh – disha Feb 08 '19 at 09:14
-
There is a confusion. If you want to save the contents in a file,save it in output-test.txt not output-test.sh . I still do not understand when you receive the error.. While executing test.sh or output-test.sh ? – daedalus_hamlet Feb 08 '19 at 09:17
-
Sorry am saving the output in output-test.txt .... Sir when i run the script from the current directory am receiving the body of the mail from output-test.txt....But now i want to run my script from other directory .....How to run my test.sh script from other directory Please help me – disha Feb 08 '19 at 09:20
-
can you please say me the command how to run test.sh from other directory.... – disha Feb 08 '19 at 09:34
-
-
-
I cannot come to a conclusion of the cause of the error without taking a look at the line4 of v1.01.sh . But try this. `chmod +x /home/centos/rr/v1.01.sh` `./home/centos/rr/v1.01.sh` – daedalus_hamlet Feb 08 '19 at 09:55
-
cat output-test.txt | mail -s "output" "abc@gmail.com" This is the 4th line....Can u help me – disha Feb 08 '19 at 10:01
-
Fine. This is where the problem is, I guess. Change the file name i.e email-body.txt to /home/centos/rr/email-body.txt in the test.sh(line 4) provided that is where email-body.txt is. So it should be like `cat /home/centos/rr/output-test.txt | mail -s "output" "abc@gmail.com"` – daedalus_hamlet Feb 08 '19 at 10:26
-