I thought that this should be straightforward, but the result is puzzling me.
When I run a bash script using the command,
sudo ./restartccpd.bash
nothing appears on the screen. Also issue of
sudo /etc/init.d/ccpd status
independently from screen after running the script produces empty, rather than showing the pid’s of the daemon. This evidences that only the pkill command is working.
The contents of the script is,
#!/bin/bash
sudo pkill -9 ccpd
sudo /etc/init.d/ccpd start
sudo /etc/init.d/ccpd status
The commands work fine when run from a terminal. But when run as a script, as pointed out above, it is not working as expected.
I tried inserting sleep command between commands, without any avail. Also, nothing appears in syslog. So, I can not diagnose the problem.
Any suggestion will be appreciated.
pkillwill kill anything containedccpdin the command name. Your script is calledrestartccpd.bash. The very first line is:So the script starts, runs
pkill(which produces no output) and promptly kills itself. Ta da!The easiest solution is to rename the script. You could also do something like:
This produces a list of proccess names and pids matching
ccpd, then removesrestartccpdfrom the list, and then kills the processes withkill.