Ask Your Question
0

Running .sh script fails returned 1 instead of one of [0]

asked 2014-10-01 16:30:42 -0600

GLN gravatar image

Folks,

I have a deployment that has to run a script (myscript.sh) at the end so a service is added on start-up. When I run the command from the command line "./myscript.sh install" it is working fine. When I try to run it from my class it is not working, it is failing with

"change from notrun to 0 failed: myscript.sh install returned 1 instead of one of [0]".

My exec looks like this:

    exec { 'add_to_startup':
        command     => 'myscript.sh install',
        cwd => "/opt/test/",
        path => "/opt/test/",           
      }

I tried to add

        user => root,

        provider => shell,

I verified that myscript.sh has #!/bin/sh at the beginning.

and I still get the same error. I must be missing something small, but I can't find out why this is not running. What am I doing wrong?

Thanks in advance. GLN

edit retag flag offensive close merge delete

Comments

try adding logoutput => on_failure, to your exec and run again. Edit your question to add any additional information.

ramindk gravatar imageramindk ( 2014-10-01 17:34:09 -0600 )edit

thanks for the advice, I will do that and post the output.

GLN gravatar imageGLN ( 2014-10-01 18:52:39 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-10-02 03:01:54 -0600

jonn gravatar image

Hi - if you run the script on the command line, what is the return code? You can get the return code like this:

# /opt/test/myscript.sh install
# echo $?

If it does return 1, then you can either modify the script so that it returns 0 on success, or use the returns attribute on the exec type to tell Puppet which return codes should be treated as successful.

edit flag offensive delete link more
0

answered 2014-10-02 09:26:39 -0600

GLN gravatar image

updated 2014-10-02 09:49:18 -0600

I found the source of the problem and kicking myself in the ... I can see the following errors

myscript.sh: line 38: which: command not found

and then

[myscript.sh] Error: this script should only be run as root

myscript.sh does have whoami='which whoami' in line 38 and then the shell script checks if whoami==root and if the user is not root it exits. so it looks like the 'which whoami' failure is causing me the problems.

When I run 'which whoami' manually I get /usr/bin/whoami , when I run myscript.sh manually it works fine but for when puppet is running myscript.sh I get command not found for 'which' and then I noticed some posting about not having environment on exec.

The solution ended up adding path

path => ":/usr/bin:/bin:/usr/sbin:/sbin",

Thanks everybody for your time and help.

GLN

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-10-01 16:30:42 -0600

Seen: 3,041 times

Last updated: Oct 02 '14