LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-25-2008, 11:24 AM   #1
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Rep: Reputation: 174Reputation: 174
Question How to make script close terminal window when complete???


Ubuntu 8.04 - I wrote a very simplistic script to backup the /home directory to a USB flash drive. I then scheduled it with gnome-schedule (run as root - gksu gnome-schedule). The script works OK and copies files as expected. It also writes the log and error files as directed. However, it opens a terminal window when it starts and displays the following message in the window when complete "Press ENTER to continue and close this window."

Here is the script:
Quote:
#!/bin/bash
echo >> /home/backup.log
echo ------------------------------------------------ >> /home/backup.log
date >> /home/backup.log

echo >> /home/backup.err
echo ------------------------------------------------ >> /home/backup.err
date >> /home/backup.err

cp -u -v -f -r /home /media/BACKUP >> /home/backup.log 2>> /home/backup.err

echo >> /home/backup.log
echo >> /home/backup.err
I have tried adding "exit" and "return" to the end of the script with no result. If I change the scheduled job to 'exec /home/backup.sh" it will run and the window will close automatically.

I am just wondering how to close the window programatically from within the script (if such a thing is possible).

Thanks,

Ken

p.s. If the USB drive is not present it does not write any errors and the log file appears to show that it copied every file. Still have to work on this phenomenon.
 
Old 08-25-2008, 11:44 AM   #2
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 32
Quote:
Originally Posted by taylorkh View Post
p.s. If the USB drive is not present it does not write any errors and the log file appears to show that it copied every file. Still have to work on this phenomenon.
It does this because when a USB drive is not mounted at /media/Backup, it looks like an empty directory to programs (or it has the files that were in it before you mounted USB to it). So there's no error because it doesn't copy anything.

Add a check in your script to make sure something is mounted at /media/Backup:
Code:
df | grep -c /media/Backup
or more fancy
Code:
df | grep -Ec <path to usb>.*/media/Backup
If it returns 1, its mounted, otherwise you make it fail with a message about no USB mounted.
 
Old 08-27-2008, 10:43 AM   #3
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Original Poster
Rep: Reputation: 174Reputation: 174
Thanks CRC123 - I will enhance my script before putting it in "production". I may mount and unmount the USB drive from within the script as well. As it is the darned thing shows up on the desktop when it automounts. I have told Gnome not to show mounted volumes however it does anyway.

Ken
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to close terminal window when launching app from command line Casket Linux - Newbie 8 11-02-2007 06:05 AM
Difference between a Shell terminal window and the KDE Linux Console terminal window? bostonantifan Fedora 2 03-25-2007 07:23 PM
Shell script window close upon completetion TuxLives Linux - General 4 01-27-2007 10:33 PM
How can a bash script findout the width of the terminal window alex.e.c Linux - Software 2 10-14-2004 11:20 AM
close a window with script box_l Programming 0 07-27-2004 07:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:15 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration