0

I'm having a strange issue when I try and execute a shell script.

when I try to execute the script with ./scriptname.sh it just immediately returns to the prompt. The script has the correct permissions set. If I copy the script to another server it executes no problem at all.

I can execute other sh scripts on the server in question with no problem.

is there a way of troubleshooting this as I am at a loss?

Thanks in advance.

0

1 Answer 1

1

Best way to check the syntax errors, you can do the below.

sh -n script_name

If you wanted to execute the script and see the flow you can use the below

sh -x script_name

Hope it helps

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks. So sh -n command returned nothing so assume no syntax errors. sh -x was interesting. When using this command to execute script on trouble server the command is cut short. Any ideas why on problem server the script is being cut short.
At the starting of the shell script, you might used the interpreter like #!/bin/sh (or) #!/bin/ksh something of that sort. Can you please check whether it has valid path?
there's nothing in the script to set interpreter. It's stopping on + case $HOSTNAME in that's the last entry on problem server.
Seems its techincal issue in your source code, may be you can check the case match or you can post the code
solved it. I thought this script had been working previously but it can't have ever worked. The case was trying to match hostname in uppercase. Changed the script to lowercase and it started working. Thanks for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.