LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Writing a script that will open a terminal window and run another script (http://www.linuxquestions.org/questions/linux-general-1/writing-a-script-that-will-open-a-terminal-window-and-run-another-script-4175450325/)

jeffery1 02-15-2013 01:00 PM

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

towheedm 02-15-2013 10:08 PM

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.

jeffery1 02-15-2013 10:17 PM

Thanks
 
Quote:

Originally Posted by towheedm (Post 4892738)
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

codergeek 02-15-2013 10:26 PM

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,

jeffery1 02-16-2013 02:01 PM

Thank you everyone
 
I want to thank both of you gentlemen for helping with that. It worked great.

codergeek 02-16-2013 03:30 PM

Happy to assist :)

Welcome to LQ!


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