Register
It is currently Mon Dec 22, 2014 9:12 am

How to detect system boot


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Sun Jan 26, 2014 9:37 am   

Joined: Sun Jan 26, 2014 7:06 am
Posts: 1
Hello guys,
I have such simple script:
Code:
#!/bin/bash
bashtrap()
{
# filtering the output an write it to file when the script is closed by CTRL+C
var=$(grep -o "[0-9]\{5,\}" file.txt)
   echo $var > file.txt
}

# when the script i killed or ended I want to make its output be written to a file.
if kill -0 $$; then
   cd ~/hashcat-0.47/
        # this script is ivoked with paramaters and its output is redirected to be written to a file called file.txt
   ./hashcat-cli32.bin -m 400 -a 3 --pw-min=12 --pw-max=12 -o rockyou.txt --remove hashfile.all -s 9087560 ?l?u?d?l?u?d?l?u?d?l?u?d?l?u?d?l?u?d?l?u?d?l?u?d?l?u?d?l?u?d?l?u?d?l?u?d > file.txt 2>&1
fi


OK so what I want is sth like this:
1. Make this script constantly running when my system is started
2. When my system is closed or reboot I want save the output to a file. Actually it happens only when script is terminate by CTRL+C combination


Top
 Profile  
 PostPosted: Wed Jan 29, 2014 8:51 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 673
Location: Des Moines, Iowa
I can get you started...

1. Cron job... use @reboot /path/to/your/script


Top
 Profile WWW  
 PostPosted: Thu Jul 10, 2014 3:05 pm   

Joined: Thu Jul 10, 2014 2:54 pm
Posts: 1
Why not just add an init script to the box. Put in the stop function whatever you are trying to run. Then add it to chkconfig to start/stop with the OS.


Top
 Profile  
 PostPosted: Mon Jul 14, 2014 9:12 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 673
Location: Des Moines, Iowa
You could, what makes that way better than just adding it to the root cron job to restart on reboot (as was the op's original request) ?

So my answer would be.
1. Add to root cron with @reboot
2. In the script add a "trap" for cleanup/exit. http://bash.cyberciti.biz/guide/Trap_statement

but, if you feel it necessary to make it more complex than it needs to be, feel free ;)


Top
 Profile WWW  
 PostPosted: Wed Oct 29, 2014 12:15 pm   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 16
To realize what you want use systemd's target shutdown, or implement a "kill" script for initV.

What you've written works. But not like you want it. You explictly watch for the end or kill of your script.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP