cron resource

asked 2017-01-23 10:37:21 -0500

Hi everyone!

I'm finding myself stuck at the cron resource. Basically I've created a shell script file with file resource and added in the crontab with the cron resource. The thing is the cron executes but the shell script file no. Can someone point me in the right direction?

node 'sysadmin-virtualbox'{
$str = "#!/bin/bash\ncurrentUser=\$whoami\nmyId=\$(id \$currentUser | awk '{print \$1}'| cut -f2 -d'='| cut -f1 -d'(')\necho 'You will be prompted for elevated rights'\nsudo apt-get -y install curlftpfs\ns"
        file{'/var/log/SYSADMIN.sh':
                ensure => present,
                content => $str,
                owner => sysadmin,
                group => sysadmin,
                mode => 775,
        }
        cron {'mountftp':
                ensure  => 'present',
                command => "cd /var/log; ./SYSADMIN.sh",
                user => 'sysadmin',
                hour => '*',
                minute => '*/2',
        }
}
edit retag flag offensive close merge delete

Comments

2

Your runs are probably failing to get any input in the cron (the auth needed for sudo) and it's failing at that point. You should verify with a more 'simple' script first, something like date > /tmp/thedate, to make sure your structure works first (it should)

DarylW gravatar imageDarylW ( 2017-01-23 14:53:24 -0500 )edit

Thank you DaryIW, that was the issue, basically in crontab the sudo was not getting elevation. I've tested it with a simple script and it works!

RaduMDragan gravatar imageRaduMDragan ( 2017-01-26 04:25:24 -0500 )edit