DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 5th December 2011
steamrent steamrent is offline
New User
 
Join Date: Dec 2011
Posts: 5
Default How do I run a shell command in a while loop?

Hi,

I am running an IRC client in OpenBSD and I choose sic because with such short amount of lines it seems very audit-able for security as opposed to larger clients such as irssi.

I usually perform:

Code:
sic -h irc.freenode.net 2>&1 | tee -a irc.log
I pipe the output of sic to tee in order to log my IRC sessions.

I'm trying to handle reconnects by running it in a while loop in the shell process and cat the initial commands into sic's stdin.

I would think to approach this by using a fifo (using the mkfifo(1) command) to redirect sic's stdin, but I'm not sure if there's a more elegant way to reconnect on ping timeouts, kills, servers going down, and just disconnects in general.

How do you suggest I go about doing this?
Reply With Quote
  #2   (View Single Post)  
Old 5th December 2011
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 7,977
Default

Hello, and welcome!

I don't use IRC or sic, but I have used loops in shells, which are easy enough. I'm not sure what you are looking for with your question. Looping syntax? For an infinite loop, perhaps:
Code:
#!/bin/sh
while :; do
     sic -h irc.freenode.net 2>&1 | tee -a irc.log
done
Reply With Quote
  #3   (View Single Post)  
Old 5th December 2011
steamrent steamrent is offline
New User
 
Join Date: Dec 2011
Posts: 5
Default

Well, I'm sure you have an understanding of general IRC even if you don't use it? In any case, sic is a very simple IRC client (that's what sic is an acronym for) that outputs the actualy IRC interaction to the shell directly, i.e.:

Code:
[~] $ sic -h irc.freenode.net 2>&1 | tee -a irc.log
zelazny.freenode.net: 12/05/11 14:45 >< NOTICE (*): *** Looking up your hostname...
zelazny.freenode.net: 12/05/11 14:45 >< NOTICE (*): *** Checking Ident
zelazny.freenode.net: 12/05/11 14:45 >< NOTICE (*): *** Found your hostname
^C
[~] $
But sometimes it disconnects, such as the common reason 'Ping timeout'. Most clients can be configured to automatically reconnected if it sees that it's not connected, but in the case of sic, it drops back into the terminal:

Code:
[~] $ sic -h irc.freenode.net 2>&1 | tee -a irc.log
zelazny.freenode.net: 12/05/11 14:45 >< NOTICE (*): *** Looking up your hostname...
zelazny.freenode.net: 12/05/11 14:45 >< NOTICE (*): *** Checking Ident
zelazny.freenode.net: 12/05/11 14:45 >< NOTICE (*): *** Found your hostname
sic shutting down: parse timeout
[~] $
When it drops back into the shell, I would like it to instead, within the same shell, have sic reconnect back with the server again, and if possible join some channels automatically (that's probably a separate project for later, unless I can manage to get shell to execute some commands within sic after it's connected).
Reply With Quote
  #4   (View Single Post)  
Old 5th December 2011
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 3,318
Default

Quote:
Originally Posted by steamrent View Post
When it drops back into the shell, I would like it to instead, within the same shell, have sic...
I suspect we all were thrown by the use of the word "shell" as it appears that you are referring to two different things -- one, a state of the application during execution, & two, the "shell" used for general system interaction -- Korn shell, bash shell, etc.

From your description, it appears under certain conditions, sic simply terminates, & this is the behavior you wish to change -- as you wish to execution to not terminate. Creating a wrapper around sic as it currently is will not change its termination logic. It appears what you want to do is change the behavior of sic itself. You will need to study the source code to see where the execution logic needs to be changed, or find a forum/mailing list which focuses on the application itself.

Now, if you don't care if a different instance is started, then I would play further with a simple wrapper as jggimi originally suggested.
Reply With Quote
  #5   (View Single Post)  
Old 6th December 2011
jsmith6134 jsmith6134 is offline
Port Guard
 
Join Date: May 2009
Posts: 10
Default

If the sic is reading from stdin that you cat'ed with initial commands sic should see an EOF (end of file). When it sees that I would expect it to exit. I would not expect it to switch from reading the cat'ed or piped input to the keyboard.

> I'm trying to handle reconnects by running it in a while loop in
> the shell process and cat the initial commands into sic's stdin.
Reply With Quote
Reply

Thread Tools
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
Running a command as a different user w/o starting the login shell Carpetsmoker General software and network 4 1st July 2011 10:33 PM
DHCP client allows shell command injection J65nko News 0 7th April 2011 01:09 AM
Full disk encryption with Loop-AES deviant085 OpenBSD Security 9 23rd November 2009 12:51 AM
Reboot loop on 7.0 upgraded to 7.1 EricM FreeBSD Installation and Upgrading 3 25th March 2009 04:25 AM
ibm eserver x225 - 7.0 installation when btx halted / endless loop underlig FreeBSD Installation and Upgrading 3 3rd August 2008 02:19 PM


All times are GMT. The time now is 09:53 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick