Fedora Linux Support Community & Resources Center
  #1  
Old 3rd February 2006, 03:08 AM
Baby Chen Offline
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
Reply With Quote
  #2  
Old 3rd February 2006, 03:39 AM
Firewing1 Offline
Registered User
 
Join Date: Dec 2004
Location: Canada
Age: 23
Posts: 9,224
Make a directory bin in your home:
Code:
mkdir ~/bin
Then, edit your script:
Code:
gedit ~/bin/name_of_your_script
Always start with this line:
Code:
#!/bin/sh
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
__________________
[+] My open source software and blog
[+] Some of my howtos: (for full list, click here)
Reply With Quote
  #3  
Old 3rd February 2006, 12:10 PM
Baby Chen Offline
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?
Reply With Quote
  #4  
Old 3rd February 2006, 12:20 PM
Baby Chen Offline
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
Reply With Quote
  #5  
Old 4th February 2006, 05:47 PM
Firewing1 Offline
Registered User
 
Join Date: Dec 2004
Location: Canada
Age: 23
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
Code:
echo -e "$TERM"
Firewing1
__________________
[+] My open source software and blog
[+] Some of my howtos: (for full list, click here)
Reply With Quote
  #6  
Old 5th February 2006, 06:15 AM
Shadow Skill Offline
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.
Reply With Quote
  #7  
Old 5th February 2006, 01:54 PM
Baby Chen Offline
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.
Reply With Quote
  #8  
Old 5th February 2006, 05:13 PM
Firewing1 Offline
Registered User
 
Join Date: Dec 2004
Location: Canada
Age: 23
Posts: 9,224
I use PyGTK (Python), so I can't help there. Google is your friend.
Firewing1
__________________
[+] My open source software and blog
[+] Some of my howtos: (for full list, click here)
Reply With Quote
  #9  
Old 5th February 2006, 10:35 PM
Shadow Skill Offline
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.
Reply With Quote
  #10  
Old 6th February 2006, 01:52 AM
Baby Chen Offline
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...
Reply With Quote
  #11  
Old 6th February 2006, 03:48 AM
Baby Chen Offline
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.
Reply With Quote
  #12  
Old 6th February 2006, 03:56 AM
Firewing1 Offline
Registered User
 
Join Date: Dec 2004
Location: Canada
Age: 23
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
__________________
[+] My open source software and blog
[+] Some of my howtos: (for full list, click here)
Reply With Quote
  #13  
Old 6th February 2006, 04:06 AM
Baby Chen Offline
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!
Reply With Quote
  #14  
Old 6th February 2006, 04:12 AM
Firewing1 Offline
Registered User
 
Join Date: Dec 2004
Location: Canada
Age: 23
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
__________________
[+] My open source software and blog
[+] Some of my howtos: (for full list, click here)
Reply With Quote
  #15  
Old 6th February 2006, 04:28 AM
Baby Chen Offline
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.
Reply With Quote
Reply

Tags
scripting, shell

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
shell scripting - please need help malaka19 Using Fedora 4 20th January 2008 03:18 PM
shell scripting haaidy Programming & Packaging 5 14th January 2008 10:42 PM
shell scripting jim Programming & Packaging 8 10th May 2005 05:18 PM


Current GMT-time: 02:43 (Saturday, 25-10-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Igarapava Travel Photos - Jaitaran - Linares Travel Photos on Instagram