 |
 |
 |
 |
| Programming & Packaging A place to discuss programming and packaging. |

3rd February 2006, 03:08 AM
|
|
Registered User
|
|
Join Date: Dec 2005
Posts: 20

|
|
|
shell scripting
Hello!
I want to make a script that would create a new terminal and automalically issue this command "tail -f /var/log/messages"
Is this possible?
Hope you can help me.
-Baby Chen
|

3rd February 2006, 03:39 AM
|
 |
Administrator
|
|
Join Date: Dec 2004
Location: Canada
Age: 22
Posts: 9,224

|
|
Make a directory bin in your home:
Then, edit your script:
Code:
gedit ~/bin/name_of_your_script
Always start with this line: Then, underneath that, start scripting.
And finally make it executable:
Code:
chmod +x ~/bin/name_of_your_script
An example for your cause would be:
Code:
#!/bin/sh
tail -f /var/log/messages
From there you can run name_of_your_script in a terminal to run the script.
Add a launcher in your panel, and tell it to "run in terminal" by ticking the checkbox. Off you go 
BTW, see my sig. Under the "References" menu I have a BASH scripting tutorial.
Firewing1
|

3rd February 2006, 12:10 PM
|
|
Registered User
|
|
Join Date: Dec 2005
Posts: 20

|
|
|
Thank you very much Firewing1.
The problem is that i dont know how to make a script that would create a new terminal and automalically issue this command "tail -f /var/log/messages" .
Do you know how to make a script like that?
|

3rd February 2006, 12:20 PM
|
|
Registered User
|
|
Join Date: Dec 2005
Posts: 20

|
|
|
I have done this script:
#!/bin/sh
TERM=linux ./messages
but it would display a messagelike this:
bash: ./messages: Text file busy
|

4th February 2006, 05:47 PM
|
 |
Administrator
|
|
Join Date: Dec 2004
Location: Canada
Age: 22
Posts: 9,224

|
|
Quote:
|
Originally Posted by Baby Chen
I have done this script:
#!/bin/sh
TERM=linux ./messages
but it would display a messagelike this:
bash: ./messages: Text file busy
|
I don't see what this does. Linux isn't a command.
Bascially, let's break it down.
TERM=linux
tells TERM variable to hold value of Linux
./messages is a seperate thing, because of the space. So it says it can't because ./messages isn't executable.
If you wanted to make the TERM variable carry the whole linux ./messages
then you'd have to do this:
Code:
TERM="linux ./messages"
Although, this won't do anything. To execute a command, you must use it like this:
$(command)
so, for example,
Code:
#!/bin/bash
TERM=$(tail -r /var/log/messages)
Will tell TERM to hold the value of whatever tail -r /var/log/messages returns. To echo the result, use
Code:
zenity --info --text "$TERM" --title "Messages"
for a GUI window, for a terminal use
Firewing1
|

5th February 2006, 06:15 AM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 1,317

|
|
|
Depending on the terminal emulator you are using you may not even need to create a script Gnome terminal for example has a flag for executing commands -e or -x.
__________________
Ware wa mutekinari.
Wa ga kage waza ni kanau mono nashi.
Wa ga ichigeki wa mutekinari.
Please vote for this bug and help me make GAYT [Go As You Type ]a standard option in Firefox.
|

5th February 2006, 01:54 PM
|
|
Registered User
|
|
Join Date: Dec 2005
Posts: 20

|
|
|
Thank you guys for your replies.
Well, I i know already how to open a new konsole that automalically issue this command "tail -f /var/log/messages. Here's my script:
#!/bin/bash
konsole -e tail -f /var/log/messages
Now my problem is how to call a shell script in the GTK+ Glade C code when ever an event in called.
Hope you can help me again.
|

5th February 2006, 05:13 PM
|
 |
Administrator
|
|
Join Date: Dec 2004
Location: Canada
Age: 22
Posts: 9,224

|
|
|
I use PyGTK (Python), so I can't help there. Google is your friend.
Firewing1
|

5th February 2006, 10:35 PM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 1,317

|
|
|
Look up the system() and exec() functions and just work them into your condition so that the script you want executed gets executed when the desired condition is met.
__________________
Ware wa mutekinari.
Wa ga kage waza ni kanau mono nashi.
Wa ga ichigeki wa mutekinari.
Please vote for this bug and help me make GAYT [Go As You Type ]a standard option in Firefox.
|

6th February 2006, 01:52 AM
|
|
Registered User
|
|
Join Date: Dec 2005
Posts: 20

|
|
@Firewing1 : i have search in the google or yahoo and found no answer...
@Shadow Skill : Thanks a lot... I will try your suggestion...
|

6th February 2006, 03:48 AM
|
|
Registered User
|
|
Join Date: Dec 2005
Posts: 20

|
|
|
ey guys! thanks a lot... i have solved already the problem... and i have another problem again...
I have tried this one:
#!/bin/bash
konsole -e tail -f /var/log/messages #log messages for Fedora Core
konsole -e tail -f /var/log/server1.group.org-bin.log #log messages for mysql
when i run the script above the konsole would only open/execute when I close/exit the first konsole.
How can i display a konsole with tabs? or two konsoles and each konsoles have different commands to run/issue...
How will i do that?
Hope you can help me again..
Last edited by Baby Chen; 6th February 2006 at 04:01 AM.
|

6th February 2006, 03:56 AM
|
 |
Administrator
|
|
Join Date: Dec 2004
Location: Canada
Age: 22
Posts: 9,224

|
|
I dont know if you can do that. Just wondering -- Why do you want to run a console? It's much easier to make the command in script form and run that from a console. Launchers can start the consoles for you. Another advantage to this approach is it works in a CLI mode. Starting konsole to do your command will not work in a CLI b/c it will complain of X not running. For now, you may think this will not be an issue, but believe me later on, when you like the CLI, or when you're SSHing it will. 
Firewing1
|

6th February 2006, 04:06 AM
|
|
Registered User
|
|
Join Date: Dec 2005
Posts: 20

|
|
Hi Firewing1...
The use of this running the script on a konsole to monitor my system through its log messages. Right now I dont have any knowledge in CLI or SSH.
I have editted my post before this one pls read... hope you understand what im saying..
TC!
|

6th February 2006, 04:12 AM
|
 |
Administrator
|
|
Join Date: Dec 2004
Location: Canada
Age: 22
Posts: 9,224

|
|
Quote:
|
Originally Posted by Baby Chen
i run the script above the konsole would only open/execute when I close/exit the first konsole.
|
Try this:
Code:
#!/bin/bash
konsole -e tail -f /var/log/messages #log messages for Fedora Core &
konsole -e tail -f /var/log/server1.group.org-bin.log #log messages for mysql &
As for what to do, you can leave it in a konsole, but personally I'd to this:
1) Change the script to:
Code:
#!/bin/bash
echo '-- MESSAGES --'
tail -f /var/log/messages #log messages for Fedora Core
echo -n '[enter] to continue';read -n 1 nothing
echo '-- MYSQL --'
tail -f /var/log/server1.group.org-bin.log #log messages for mysql
then make a launcher in KDE that does
Code:
konsole -e the_script_name
That way, you still see a konsole, there's no difference, but it will not work from CLI, SSH, or anything else.
Firewing1
|

6th February 2006, 04:28 AM
|
|
Registered User
|
|
Join Date: Dec 2005
Posts: 20

|
|
|
[qoute]
#!/bin/bash
konsole -e tail -f /var/log/messages #log messages for Fedora Core &
konsole -e tail -f /var/log/server1.group.org-bin.log #log messages for mysql
[/qoute]
I have tried that one but its not the output i want to.
I want to open a konsole simlutaneously in one script.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Current GMT-time: 11:51 (Saturday, 25-05-2013)
|
|
 |
 |
 |
 |
|
|