LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-27-2010, 12:51 AM   #1
Farrukh Fida
Member
 
Registered: Jun 2006
Location: Dubai
Distribution: Cent OS
Posts: 34

Rep: Reputation: 15
Unhappy /bin/sh: /etc/cron.d/redial: Permission denied


Hi,

I write following script.

#!/bin/bash

TEST=$(ifconfig | grep "ppp")

if [ -z "$TEST" ]
then
pptp xxx.xxx.xxx.37 call testVPN_original
fi

echo $TEST
SUB=${TEST:0:3}

YY="ppp"

echo $YY
echo $SUB
if [ $SUB == $YY ];
then
ping -c 2 192.168.0.2
route add default gw 192.168.0.2
fi


and named it as "redial" and set permission chmod u+x redial (chmod 755 redial)

ls -l
-rwxr-xr-x 1 root root 287 Jan 21 00:19 redial

I save this file in /etc/crond.d/redial
manually this script is running correctly but when I add this script to crontab it never runs. following is my crontab file.

SHELL=/bin/sh
PERL=/usr/bin/perl
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=""
HOME=/
22 5 * * * /usr/bin/perl /var/adm/bin/registry.pl > /dev/null 2>&1
16 * * * * /var/lib/asterisk/bin/freepbx-cron-scheduler.php
22 20 * * * /etc/webmin/cron/tempdelete.pl
2 * * * * /bin/sh /etc/cron.d/redial

2 * * * * /bin/sh /etc/cron.d/redial is not running by crontab producing following error

/bin/sh: /etc/cron.d/redial: Permission denied

I've following cron files
cron.d/
cron.daily/
cron.deny
cron.hourly/
cron.monthly/
crontab
cron.weekly/

no cron.allow file means all user are allowed.
cron.deny file is empty.

I don't have any idea regarding this deny.
Please help
 
Old 01-27-2010, 01:16 AM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
One or two things are unclear here..

1) Near the end of your post, you list some FOLDERS, not files. And I don't believe the cron program you are using, actually cares what the names of those folders are; they are more for your convenience than for the cron program.

2) What cron program are you using? I am assuming Dillons Cron, but if I'm wrong, please tell us. If it is Dillons (which I use), I don't see in the man pages any reference to a "cron.allow" or 'cron.deny' file or folder. Are you sure this is relevant?

3) It looks like a simple permissions issue. I wonder if the fact that you have the "/bin/sh" on the crontab line is causing the problem. Dillons Cron executes commands using "/bin/sh -c" already, so putting /bin/sh there (considering that you already have a shabang atop your script anyway) may be the problem.

First thing I'd do, would be remove the /bin/sh from the crontab entry.

Sasha

Last edited by GrapefruiTgirl; 01-27-2010 at 01:17 AM. Reason: typo
 
Old 01-27-2010, 01:39 AM   #3
Farrukh Fida
Member
 
Registered: Jun 2006
Location: Dubai
Distribution: Cent OS
Posts: 34

Original Poster
Rep: Reputation: 15
Thanks for help.

1) cron.deny is file not directory
2) I'm not sure which cron program I'm using because I'm using CentOS 5 and cron is pre-installed.
3) yes remove /bin/sh from cron now it looks like following

SHELL=/bin/sh
PERL=/usr/bin/perl
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=""
HOME=/
22 5 * * * /usr/bin/perl /var/adm/bin/registry.pl > /dev/null 2>&1
16 * * * * /var/lib/asterisk/bin/freepbx-cron-scheduler.php
22 20 * * * /etc/webmin/cron/tempdelete.pl
2 * * * * /etc/cron.d/redial

but still not running
 
Old 01-27-2010, 01:53 AM   #4
sohail0399
Member
 
Registered: Oct 2008
Location: Pakistan, Islamabad
Distribution: CentOS, Fedora, Solaris
Posts: 154

Rep: Reputation: 23
problem may be is in

chmod u+x redial

this gives on my system

-rwxr-xr-x 1 AAA AAA 253 Jan 27 12:49 redial

which is not same as 755

for
chmod 755 redial

-rwxr-xr-x 1 AAA AAA 253 Jan 27 12:49 redial
 
Old 01-27-2010, 01:56 AM   #5
Farrukh Fida
Member
 
Registered: Jun 2006
Location: Dubai
Distribution: Cent OS
Posts: 34

Original Poster
Rep: Reputation: 15
in
/var/log/cron

(*system*) BAD FILE MODE (/etc/cron.d/redial)

means what should I set

chmod 755 redial or chmod u+x redial
 
Old 01-27-2010, 05:08 AM   #6
Farrukh Fida
Member
 
Registered: Jun 2006
Location: Dubai
Distribution: Cent OS
Posts: 34

Original Poster
Rep: Reputation: 15
Hi
(*system*) BAD FILE MODE (/etc/cron.d/redial) error has gone when I change my script's pemission from 755 to 644

now my cron log shows every 2 min it runs(read) /etc/cron.d/redial.sh


Jan 21 15:12:01 xxxx crond[6811]: (root) CMD (/etc/cron.d/redial.sh)
Jan 21 15:14:01 xxxx crond[6813]: (root) CMD (/etc/cron.d/redial.sh)
Jan 21 15:16:01 xxxx crond[6838]: (root) CMD (/etc/cron.d/redial.sh)
Jan 21 15:16:01 xxxx crond[6840]: (root) CMD (/var/lib/asterisk/bin/freepbx-cron-scheduler.php)
Jan 21 15:18:01 xxxx crond[6845]: (root) CMD (/etc/cron.d/redial.sh)
Jan 21 15:20:01 xxxx crond[6850]: (root) CMD (/etc/cron.d/redial.sh)
Jan 21 15:22:01 xxxx crond[6852]: (root) CMD (/etc/cron.d/redial.sh)
Jan 21 15:24:01 xxxx crond[6862]: (root) CMD (/etc/cron.d/redial.sh)
Jan 21 15:26:01 xxxx crond[6922]: (root) CMD (/etc/cron.d/redial.sh)
Jan 21 15:28:01 xxxx crond[6924]: (root) CMD (/etc/cron.d/redial.sh)
Jan 21 15:30:01 xxxx crond[6926]: (root) CMD (/etc/cron.d/redial.sh)
Jan 21 15:32:01 xxxx crond[6931]: (root) CMD (/etc/cron.d/redial.sh)
Jan 21 15:34:01 xxxx crond[6935]: (root) CMD (/etc/cron.d/redial.sh)
Jan 21 15:36:01 xxxx crond[6941]: (root) CMD (/etc/cron.d/redial.sh)
Jan 21 15:38:01 xxxx crond[6943]: (root) CMD (/etc/cron.d/redial.sh)
Jan 21 15:40:01 xxxx crond[6945]: (root) CMD (/etc/cron.d/redial.sh)
Jan 21 15:42:01 xxxx crond[6951]: (root) CMD (/etc/cron.d/redial.sh)

But never happen according to my script.

I don't know why it is not running when 755 is set as file permission.

Last edited by Farrukh Fida; 01-27-2010 at 05:17 AM.
 
Old 01-27-2010, 05:39 AM   #7
Farrukh Fida
Member
 
Registered: Jun 2006
Location: Dubai
Distribution: Cent OS
Posts: 34

Original Poster
Rep: Reputation: 15
Hi everyone,

Thanks for your help. Now it is working fine.

I just change the script permission to

chmod u+x /etc/cron.d/redial.sh


and following is my crontab entry

*/2 * * * * /etc/cron.d/redial.sh

It runs after 2 mins and runs script(redial.sh)

This script is providing me consistent connection to my VPN server if VPN breaks it redial after 2 min.

Thanks.

Farrukh Fida.
 
Old 01-27-2010, 09:55 AM   #8
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Nice glad you got it sorted out.

So it appears that the script to be executed needed to have the .sh extension on it? Besides removing the /bin/sh from the front of the entry?
 
Old 01-27-2010, 11:46 PM   #9
Farrukh Fida
Member
 
Registered: Jun 2006
Location: Dubai
Distribution: Cent OS
Posts: 34

Original Poster
Rep: Reputation: 15
Yes exactly
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
/bin/.: Permission denied aizkorri Programming 9 03-17-2010 01:33 PM
su: /bin/bash: Permission denied fedora4002 Linux - Security 5 01-29-2010 08:46 AM
./bin/sh : Permission denied OliB Linux - Software 19 06-02-2008 02:59 AM
su: /bin/bash: Permission denied dwarf007 Linux - General 10 01-20-2006 04:32 PM
/bin/sh Permission Denied vi0lat0r Linux - Newbie 1 08-26-2003 07:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration