What's new

How can I verify running script?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Bamsefar

Senior Member
I thought I knew this one, but with Busybox and the limitations inside this environment, well I guess I need help :)

I have a script: /jffs/scripts/CheckIfHome

Now I start it in services-start with: source /jffs/scripts/CheckIfHome &

And then I tried a few ways to verify that it is running - but it is stealth for sure. ps command well it is not supported as I am used (ex linux/solaris sysadm). I can see that the scripts run, since the function is there, and the sleep statement seems to be executed (although according to ps command it seems to shift PID all the time). But I have not found out how to verify if the scripts runs with less than check if a certain map is created or not...

So okay it is in the middle of the night here in Sweden, and my head is actually in Sydney time... And well anyone has any ideas?
 
Well there are many ways of doing this. How about using the "pidof" command?
Code:
# pidof bogus
# pidof u2ec
501 500 477
# pidof dnsmasq
644

Edit: Actually, forget that. The process running would be "sh" not your script. :rolleyes:

How about the old faithful:
Code:
# ps | grep CheckIfHome | grep -v grep
# echo $?
 
Last edited:
Well it is just that well I can't find the process...

Example: ps | grep CheckIfHome
Will result in just finding the grep command and not the original CheckIfHome...

Example: pidof CheckIfHome
Result is empty.

It's like the process is not there - however the functionality that the script provides (check if a number of MAC addresses are on the WiFi with wl command) works 100% all the time. I just can not find it...
 
Put some 'logger' statements in your script to write status to the syslog?
 
Well that I can, but what I need to do, is to be able to restart the process, and most important make sure there is only ONE instance of the script running...
 
Well it is just that well I can't find the process...

Example: ps | grep CheckIfHome
Will result in just finding the grep command and not the original CheckIfHome...

Example: pidof CheckIfHome
Result is empty.

It's like the process is not there - however the functionality that the script provides (check if a number of MAC addresses are on the WiFi with wl command) works 100% all the time. I just can not find it...
Ah, of course. :rolleyes: It's because you're using "source". Any reason for that? Why not just "shell out" as a new process?
 
You could have the logger statement include the pid.....at least for debug it might help you track down how the process is named.
Code:
scr_name="$(basename $0)[$$]"
echo "some message" | logger -t $scr_name
 
Ah, of course. :rolleyes: It's because you're using "source". Any reason for that? Why not just "shell out" as a new process?

I think that is a good question. I think I tried nohup but if my memory is correct that is not supported in AsusWRT...

What I need, from start-services, is to start this script in the background, and just let it run. In the script I need to verify that it is not already running. If running already I guess it would be nice to kill the old one...
 
You could have the logger statement include the pid.....at least for debug it might help you track down how the process is named.
Code:
scr_name="$(basename $0)[$$]"
echo "some message" | logger -t $scr_name

Good Idea - I'll add the code :)
 
Just changed to nohup - works like a charm. And now I can see the script under ps - and now I can do what I need. Wonder why I choosed source.....?

Hmm.... well logging does not seem to work - I have a few (3) logging statements, and I can't find them.....
 
Correction, now I found the logger messages - can't say why I did not find them before - I guess I am getting tired or something (it is in the middle of the night here...).
 

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top