LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 05-27-2007, 07:28 AM   #1
SharpyWarpy
Member
 
Registered: Feb 2003
Location: Florida
Distribution: Fedora 16x_64
Posts: 565

Rep: Reputation: 62
Graceful closing of commands run in a terminal


I haven't done any bash scripting for awhile and I've forgotten some things.
I've got this little script I run from a terminal in Gnome, it opens a terminal, decrypts my password file and opens it with "less" and when I close less it encrypts the file and deletes the decrypted file. The problem comes if and when I choose to close the terminal by right-click and "close", it doesn't delete the unencrypted file.
My question is isn't there some way of making it catch the sighup and deleting the file? I tried

case $SIGHUP
do rm -f .passwords
done
esac

but I get all sorts of rookie error reports. Help! Thanks.
 
Old 05-27-2007, 07:56 AM   #2
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,185

Rep: Reputation: 468Reputation: 468Reputation: 468Reputation: 468Reputation: 468
Been a while since I've done it. You can use the "trap" command (this is a bash builtin) to define what to do when you receive a SIGHUP. You'd set the trap action in the script.

man bash

locate trap (at the beginning of a line - you'll see it multiple times before you get to the actual command).
 
Old 05-27-2007, 08:30 AM   #3
SharpyWarpy
Member
 
Registered: Feb 2003
Location: Florida
Distribution: Fedora 16x_64
Posts: 565

Original Poster
Rep: Reputation: 62
Quote:
Originally Posted by jlightner
Been a while since I've done it. You can use the "trap" command (this is a bash builtin) to define what to do when you receive a SIGHUP. You'd set the trap action in the script.

man bash

locate trap (at the beginning of a line - you'll see it multiple times before you get to the actual command).
Okay, thanks jlightner. I included the following in the script and it works.

trap 'rm -f /rbandmb/.passwords' SIGHUP

"/rbandmb" being my home directory. Thanks again.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
making a script that opens terminal and enter commands into that terminal Cinematography Linux - General 8 12-16-2008 10:34 AM
Fedora 6 - problem with terminal window closing immediately. bostonantifan Fedora 5 03-25-2007 07:21 PM
Not sure how to run terminal commands at startup mandrakethepenguin Linux - Newbie 4 01-04-2006 08:04 PM
Help to create a script to open a terminal and run commands in it. Brian1 Linux - Software 6 02-07-2005 06:46 PM
Closing a port in linux terminal..any command?? fhameed Linux - Security 1 07-20-2004 11:46 PM


All times are GMT -5. The time now is 11:10 PM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration