Shell Permission problem with bash script

FreeBSD-12.2p9

On a FreeBSD host I have the following in the crontab for root:
Code:
@reboot /usr/local/bin/bash -c '/var/spool/hp3000/scripts/np4179_rpt.job'

When I rebooted this system I received this message:

Code:
/usr/local/bin/bash: line 1: /var/spool/hp3000/scripts/np4179_rpt.job:
Permission denied

The file `/var/spool/hp3000/scripts/np4179_rpt.job` has the following permissions:
Code:
-rw-r--r--  1 hp3000  hp3000  221 May 28 10:12 /var/spool/hp3000/scripts/np4179_rpt.job

Ir contains the following code:
Code:
export HPNP=4179 ; socat TCP4-LISTEN:${HPNP},bind=192.168.216.179,fork,reuseaddr,su=hp3000 SYSTEM:'gpcl6 -dNOSAFE -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=/var/spool/hp3000/np${HPNP}/HP3000-RPT-$(date -Iseconds).pdf -' &

I can run /usr/local/bin/bash -c '/var/spool/hp3000/scripts/np4179_rpt.job' from the command line as root and it starts without difficulty. I do not understand why it has a permission problem for root running from cron. I can see that the script is not owned by root, but that should make no difference since it can be read by anyone.

What is the problem with this set up?
 
I suspect it might be the bind that's failing. If the machine doesn't have that IP address you can't bind a service to that IP address. Maybe it starts too early, before the IP addresses have been assigned?
 
I suspect it might be the bind that's failing. If the machine doesn't have that IP address you can't bind a service to that IP address. Maybe it starts too early, before the IP addresses have been assigned?
I had not thought of that. You are likely right. Now my question is, how can one delay the start of a reboot script until after the interfaces are all up?
 
Add a sleep 60; at the start of your script. That'll sleep the script for 60 seconds, that might be enough.
 
The file `/var/spool/hp3000/scripts/np4179_rpt.job` has the following permissions:
Code:
-rw-r--r-- 1 hp3000 hp3000 221 May 28 10:12 /var/spool/hp3000/scripts/np4179_rpt.job
You might want to add the 'x' bit to your file perms, like this: # chmod 755 /var/spool/hp3000/scripts/np4179_rpt.job. Your current permissions are 644.
 
You might want to add the 'x' bit to your file perms,
Not required, script isn't executed directly but through /usr/local/bin/bash.

Code:
dice@armitage:~/test % cat test.sh
#!/bin/sh

echo Hello World!
dice@armitage:~/test % sh test.sh
Hello World!
dice@armitage:~/test % ./test.sh
./test.sh: Permission denied.
dice@armitage:~/test % chmod +x test.sh
dice@armitage:~/test % ./test.sh
Hello World!
 
Nice demo, covacat and SirDice . I actually learned something from it. I would still use the Execute bit anyway, just to be on the safe side, and not have to hunt down a command-line argument that may need to be adjusted in several .conf files.
 
Back
Top