LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-06-2005, 06:11 PM   #1
Brian1
LQ Guru
 
Registered: Jan 2003
Location: Seymour, Indiana
Distribution: Distribution: RHEL 5 with Pieces of this and that. Kernel 2.6.23.1, KDE 3.5.8 and KDE 4.0 beta, Plu
Posts: 5,700

Rep: Reputation: 65
Help to create a script to open a terminal, put it on the KDE and run commands in it.


Been trying to figure out how to run a script that will start a small or minimized terminal window in KDE 3.3.x on the desktop and then run a command in it automatically. Then when done I close the minimized window and the program quits. Or something I can control on the desktop. The script is to start the app ' slmodemd --alsa ' command to start access to my internal intel win modem.

Example:
Create a script called startmodem
In startmodem it needs to open a terminal screen ( options smaller than normal or minimized sized). Then when the terminal is open run slmodemd --alsa.
When I am done I can hit the close or X in the conner.
Then the orginal script startmodem then terminates

Another option is create a script called startmodem
In startmodem it needs a create tool box or something that indicates that slmodemd --alsa might be running. When I am done I can hit the close or X in the conner.

Another option is possible write one script to start slmodemd --alsa then a second script that finds the running process and can kill it.

I just want to click an icon on the desktop to do either above ideas.

Thank you for your time and help.
Brian1
" Google the Linux way @ http://www.google.com/linux "

Last edited by Brian1; 02-06-2005 at 06:12 PM.
 
Old 02-06-2005, 06:20 PM   #2
leonscape
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Debian SID / KDE 3.5
Posts: 2,313

Rep: Reputation: 48
You could use kdialog instead on running console.

Code:
#!/bin/sh
slmodemd --alsa
if [ #? -ne 0 ]; then
    kdialog --error "Problem doing slmodemd --alsa"
else
    kdialog --msgbox "Successful doing slmodemd --alsa"
fi
save this file, then "chmod +x thefile" after that create a desktop link for it.
 
Old 02-06-2005, 06:59 PM   #3
Brian1
LQ Guru
 
Registered: Jan 2003
Location: Seymour, Indiana
Distribution: Distribution: RHEL 5 with Pieces of this and that. Kernel 2.6.23.1, KDE 3.5.8 and KDE 4.0 beta, Plu
Posts: 5,700

Original Poster
Rep: Reputation: 65
Did not work.

Thanks for the quick help. That does not print anything to the screen. Reason is when I run ' slmodemd --alsa ' it waits till one hits ctrl-C to stop it. It will not go beyond that point to execute the next line in the script.

This is what running the command in a terminal outputs
Code:
[crusher58@lcomp58 networksetup]$ ./modemstart
SmartLink Soft Modem: version 2.9.9 Aug  7 2004 09:17:27
symbolic link `/dev/ttySL0' -> `/dev/pts/5' created.
modem `hw:1' created. TTY is `/dev/pts/5'
Use `/dev/ttySL0' as modem device, Ctrl+C for termination.
./modemstart: line 5: syntax error near unexpected token `else'
./modemstart: line 5: `else'
[crusher58@lcomp58 networksetup]$
Now it is waiting at line ' Use `/dev/ttySL0' as modem device, Ctrl+C for termination. ' .When I hit ctrl-c I get the rest. Also there is no dialog box sent to the desktop.

Contents of startmodem
Code:
#!/bin/sh
/sbin/slmodemd --alsa
if [ #? -ne 0 ]; then
    kdialog --error "Problem doing slmodemd --alsa"
else
    kdialog --msgbox "Successful doing slmodemd --alsa"
fi
After seeing this reponce I think what I will need to do is open a terminal window and in it execute the slmodemd --alsa command. I can put up the terminal with ' konsole ' and probably figure out to make a special size. But have yet to figure out how to start the slmodemd --alsa line in it.

Thanks for your time and help there leonscape
Brian1
" Google the Linux way @ http://www.google.com/linux "

Last edited by Brian1; 02-06-2005 at 07:42 PM.
 
Old 02-07-2005, 12:10 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,369

Rep: Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753
That code looks wrong to me; try this version:
Code:
#!/bin/bash
/sbin/slmodemd --alsa
if [[ $? -ne 0 ]]
then
    kdialog --error "Problem doing slmodemd --alsa"
else
    kdialog --msgbox "Successful doing slmodemd --alsa"
fi
 
Old 02-07-2005, 05:25 PM   #5
Brian1
LQ Guru
 
Registered: Jan 2003
Location: Seymour, Indiana
Distribution: Distribution: RHEL 5 with Pieces of this and that. Kernel 2.6.23.1, KDE 3.5.8 and KDE 4.0 beta, Plu
Posts: 5,700

Original Poster
Rep: Reputation: 65
Hi chrism01

That does work better and does display the to the screen with either error depending on action. Still not quite what I want. But I did learn how to use if, then, else, and kdialog.

What happens, when I click on the icon to the script it starts but does don't send any output to screen or a way to stop it. I can kill the process and the error kdialog comes up which is good. When I run in a terminal it starts and when I hit ctrl-c to stop it, the sucessful kdialog displays.

Close but not quite there. It just may not be possible to do.I will work on this my self later after learning a little more on perl or C.

Thanks again for everybody's help.
Brian1
" Google the Linux way @ http://www.google.com/linux "
 
Old 02-07-2005, 06:05 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,369

Rep: Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753
Glad to help. You may find these informative:
http://www.icon.co.za/~psheer/book/index.html.gz
http://www.tldp.org/LDP/abs/html/index.html
If you don't want it tying up the terminal/screen try:
nohup /sbin/slmodemd --alsa &
ie detach from terminal & send it to the background
 
Old 02-07-2005, 06:46 PM   #7
Brian1
LQ Guru
 
Registered: Jan 2003
Location: Seymour, Indiana
Distribution: Distribution: RHEL 5 with Pieces of this and that. Kernel 2.6.23.1, KDE 3.5.8 and KDE 4.0 beta, Plu
Posts: 5,700

Original Poster
Rep: Reputation: 65
Thanks for the links there. I did get something working for now. It does use 2 scripts though.

startmodem script
Code:
#!/bin/bash

kdialog --msgbox "Started slmodemd --alsa"
/sbin/slmodemd --alsa
kdialog --msgbox "Stopped slmodemd --alsa"
modemstop script
Code:
killall slmodemd
Now the startmodem displays the first message and then starts slmodemd. If slmodemd failed then the the stopped message would display imediately. Or if the app stops for some reason.

Then the modemstop kills slmodemd and lets the the stop message display from the modemstart script display.

In the modemstart script I could probably add an if then else option that if it failed to run then display Error Occurred and if closed successfully then display Stopped slmodemd. Will work on that.

This will work for me now. Love the simplicity of scripts.
Thanks again to all.
Brian1
" Google the Linux way @ http://www.google.com/linux "
 
  


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
making a script that opens terminal and enter commands into that terminal Cinematography Linux - General 8 12-16-2008 10:34 AM
how to create a script that can goto different dir and also to run prompts ann124 Programming 5 11-29-2004 12:48 PM
Script to Run the Same Commands on a List of Files Chryzmo Programming 1 10-03-2004 08:34 AM
Creating a script to run two commands anjaan Programming 11 06-15-2004 02:51 AM
run 2 commands in a script ddpicard Linux - General 10 06-13-2003 04:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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