Not able to run shell Script

Hi,

1) When I run a script name myscript.sh, I do not see any error nor does the script get executed. What can be the possible reason? This was an interview question asked recently

eg.

sh myscript.sh

2) I manually check if my directory is being updated every 5 mins. How can I automate this shell scripting?

1) try sh -x or bash -x
2) automating use crontab

Hi Bashar,

I believe 1) try sh -x or bash -x
would only help if the script ran.

But in my case, the script did not run and I did not get any error either.
This was the scenario given to me during an interview.

Question:
------------
When I run a script name myscript.sh, I do not see any error nor does the script get executed. What can be the possible reason?

Answer:
------------
First whether the script have executable permission(+x) permission. If the script did not have executable permission it will not run as a local user

If you are running the script as root user executable permission is not required.

If you run a script and no errors available means, First open the shell script and see what content is available inside it.

  1. Question
    -----------------

I manually check if my directory is being updated every 5 mins. How can I automate this shell scripting?

Answer:
-----------

One word "crontab".

Go to google and search for crontab with examples in linux lot of articles are available.

if just returned to command prompt then maybe the script does nothing?

Thank you for your reply guys.
I guess the file would have nothing in it.

This script has something in it but I have named it useless.sh...

#/bin/bash --posix
NOP()
{
	:
}
NOP
exit 1

Results...

Last login: Mon Nov 11 20:00:59 on ttys000
AMIGA:barrywalker~> chmod 755 useless.sh
AMIGA:barrywalker~> ./useless.sh
AMIGA:barrywalker~> echo "$?"
1
AMIGA:barrywalker~> _

As you can see it works perfectly the way you described and my exit _code_ was correct.
There were no error reports, nothing appeared on screen and and my prompt returned as normal.

Maybe your script IS running but without seeing any of your attempts we can never know...