LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 02-15-2013, 01:00 PM   #1
jeffery1
LQ Newbie
 
Registered: Feb 2013
Posts: 16

Rep: Reputation: Disabled
Writing a script that will open a terminal window and run another script


Good Afternoon Ladies and Gentlemen,
I am trying to write a script that will open a new terminal windows and call on a script to check certain items. I would like help if anyone has any ideas. Here is what I have

if zenity --question --text "Did you run the '*******' script to check loging to *****? Press OK for YES and CANCEL for NO"; then
zenity --width=300 --width=200 --info --title "Good!" --text "Good"
else
zenity --width=300 --width=200 --error --title "Will Check Now!" --text "Will Login to *** **** Machines"; exit
fi

If someone hit cancel I want it to open a new terminal window and run a script to check if you can login to certain things. Please help if you can
 
Old 02-15-2013, 10:08 PM   #2
towheedm
Member
 
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Stretch
Posts: 612

Rep: Reputation: 125Reputation: 125
For starters, please use code tags around your code. It makes it easier to read and preserves formatting.

Depending on the terminal emulator you're using, you can open a terminal and run a script.

Let's say you're using the Terminal emulator, and you want to run a script named check-credentials.sh, in your present terminal you would open a new terminal window and run the script with:
Code:
terminal -e="/path/to/check-credentials.sh"
For more info on the terminal command see:
Code:
man terminal
Of course if you use another emulator such as xterm, the construct would be different.
So your code would be"
Code:
if zenity --question --text "Did you run the '*******' script to check logging to *****?\n\nPress OK for YES and CANCEL for NO"; then
  zenity --width=300 --width=200 --info --title 'Good!' --text "Good"
else
  zenity --width=300 --width=200 --error --title 'Will Check Now!' --text "Will Login to *** **** Machines"
  terminal -e="/path/to/check-credentials.sh"
fi
exit 0
Notice the two changes in RED. The ! is a reserved character in BASH and as such must either be escaped to become a literal character or placed within strong quotes.

BTW: Zenity on my machine, showed OK and Cancel buttons instead of Yes and No.

Hope it helps.

Last edited by towheedm; 02-15-2013 at 10:13 PM.
 
1 members found this post helpful.
Old 02-15-2013, 10:17 PM   #3
jeffery1
LQ Newbie
 
Registered: Feb 2013
Posts: 16

Original Poster
Rep: Reputation: Disabled
Talking Thanks

Quote:
Originally Posted by towheedm View Post
For starters, please use code tags around your code. It makes it easier to read and preserves formatting.

Depending on the terminal emulator you're using, you can open a terminal and run a script.

Let's say you're using the Terminal emulator, and you want to run a script named check-credentials.sh, in your present terminal you would open a new terminal window and run the script with:
Code:
terminal -e="/path/to/check-credentials.sh"
For more info on the terminal command see:
Code:
man terminal
Of course if you use another emulator such as xterm, the construct would be different.
So your code would be"
Code:
if zenity --question --text "Did you run the '*******' script to check logging to *****?\n\nPress OK for YES and CANCEL for NO"; then
  zenity --width=300 --width=200 --info --title 'Good!' --text "Good"
else
  zenity --width=300 --width=200 --error --title 'Will Check Now!' --text "Will Login to *** **** Machines"
  terminal -e="/path/to/check-credentials.sh"
fi
exit 0
Notice the two changes in RED. The ! is a reserved character in BASH and as such must either be escaped to become a literal character or placed within strong quotes.

BTW: Zenity on my machine, showed OK and Cancel buttons instead of Yes and No.

Hope it helps.
towheedm,

Thanks I'll try it out tomorrow
 
Old 02-15-2013, 10:26 PM   #4
codergeek
Member
 
Registered: Dec 2012
Posts: 52

Rep: Reputation: 7
Code:
#!/bin/bash 

if zenity --question --text="Did you run the '*******' script to check loging to *****? Press YES for YES and CANCEL for NO" --cancel-label="Cancel"; then
zenity --width=300 --width=200 --info --title='Good!' --text="Good"
else
zenity --width=300 --width=200 --error --title='Will Check Now!' --text="Will Login to *** **** Machines" ; xterm -e top
fi
I wrote this test script close to what you needed. It will:

Ask Did you run the '*******' script to check loging to *****? Press OK for YES and CANCEL for NO

If you press YES, it will display the Good message and exit.

If you click on cancel it will display Will Check Now!". You click OK and a new console window will open to run a script or command. In this example I have the top command (in red) open a new window. Just replace top with your script to run.

The script uses the exit status of zenity to test true or false or 0 or 1,

Last edited by codergeek; 02-16-2013 at 03:45 PM.
 
Old 02-16-2013, 02:01 PM   #5
jeffery1
LQ Newbie
 
Registered: Feb 2013
Posts: 16

Original Poster
Rep: Reputation: Disabled
Thumbs up Thank you everyone

I want to thank both of you gentlemen for helping with that. It worked great.
 
Old 02-16-2013, 03:30 PM   #6
codergeek
Member
 
Registered: Dec 2012
Posts: 52

Rep: Reputation: 7
Happy to assist

Welcome to LQ!

Last edited by codergeek; 02-16-2013 at 03:44 PM.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Write a script to open a terminal and run a few commands. jmdennis1987 Linux - General 27 11-18-2010 02:24 PM
[SOLVED] perl script tp open an xterm window and run a command. casperdaghost Linux - Newbie 2 07-25-2010 02:49 AM
[SOLVED] Run Script In New Window & Keep Window Open Ben2K Programming 2 07-06-2010 01:28 AM
How do i run a script upon bootup, but in a terminal window xmrkite Linux - Software 6 09-29-2008 03:59 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

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:14 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