Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230
simple bash stdin question
- utrrrongeeb
- Posts: 254
- Joined: 2006-05-14 09:48
- Location: Eastern Canada
simple bash stdin question
I'm new to shell scripts, and I haven't got around to reading about them, but I need to write a script for warning everyone about power failures from the UPS. (recently at http://forums.debian.net/viewtopic.php?t=6944 ) What I want to know how to do is reading a chunk of data from stdin from a pipe. It sounds like it might involve the read command, but I'm not sure exactly how it should be done. Please respond if you can tell me how to do this.
utrrrongeeb formerly lecaro
Art #429775 on 'Etch' 4.0r0
Art #429775 on 'Etch' 4.0r0
For a very stupid implementation, use this:
It will read lines from the standard input, and print the readed lines. You'll probably want to replace the echo line with your handling code. You cat pipe anything into this script.
Code: Select all
while true; do
read LINE || break
echo "--> $LINE"; # Do your handling here
done
- utrrrongeeb
- Posts: 254
- Joined: 2006-05-14 09:48
- Location: Eastern Canada
Thanks for responding; What C command can handle a chunk of stdin from a pipe? I know C slightly better than bash; my main language is Java, which is useless for shell scripts.
Also, what are the main flaws with the 'very stupid implementation'?
Also, what are the main flaws with the 'very stupid implementation'?
utrrrongeeb formerly lecaro
Art #429775 on 'Etch' 4.0r0
Art #429775 on 'Etch' 4.0r0
- utrrrongeeb
- Posts: 254
- Joined: 2006-05-14 09:48
- Location: Eastern Canada
import os # load the os module that gives all these cool functions, only do it once
os.system("command")
If you want to capture the output:
x = os.popen("command")
print x.read()
x.write("this will be sent to the program which i opened")
x.close() # an open process is simply an open file, you can read and write and close it like normal
As you can see there is a reason why I don't like doing complex shell scripts anymore.
os.system("command")
If you want to capture the output:
x = os.popen("command")
print x.read()
x.write("this will be sent to the program which i opened")
x.close() # an open process is simply an open file, you can read and write and close it like normal
As you can see there is a reason why I don't like doing complex shell scripts anymore.
- utrrrongeeb
- Posts: 254
- Joined: 2006-05-14 09:48
- Location: Eastern Canada
- utrrrongeeb
- Posts: 254
- Joined: 2006-05-14 09:48
- Location: Eastern Canada
I'm changing problems now. The script I'm trying to write has the job of receiving stdin from a pipe, calling wall with that input, and then putting an alert on everyone's X desktop with the same message. I don't know Python well at all, but here's what I have at the moment:
The reading part and the wall part work, but not the alert dialog part.
Could someone please explain what to do differently, if it is possible to do this?
Code: Select all
#!/usr/bin/python
import sys
import os
li = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,50]
msgstr = sys.stdin.read(1024)
os.system("echo \""+msgstr+"\" | wall")
for itr in li:
os.system("zenity --display=:%d.0 --error --text=%s " % (itr,msgstr))
Could someone please explain what to do differently, if it is possible to do this?
utrrrongeeb formerly lecaro
Art #429775 on 'Etch' 4.0r0
Art #429775 on 'Etch' 4.0r0
- utrrrongeeb
- Posts: 254
- Joined: 2006-05-14 09:48
- Location: Eastern Canada
- utrrrongeeb
- Posts: 254
- Joined: 2006-05-14 09:48
- Location: Eastern Canada
- utrrrongeeb
- Posts: 254
- Joined: 2006-05-14 09:48
- Location: Eastern Canada
I'm considering writing a program that runs when you login to X, that checks a file for modifications and alerts you if anything is added. However, any advice on better methods to accomplish the goal here (a method to alert everyone using X of an event from the command line), please post!
utrrrongeeb formerly lecaro
Art #429775 on 'Etch' 4.0r0
Art #429775 on 'Etch' 4.0r0
Take a look at xmessage (or gmessage for "funny characters") and its '-file' option. Not quite what you're looking for but a few lines of code could fix that. For some idea how to run it at log-on, check out the xsession examples from the debian-reference package. (Could be in /usr/share/doc/Debian/reference/examples/ if it's installed.)lecaro wrote:I'm considering writing a program that runs when you login to X, that checks a file for modifications and alerts you if anything is added.
- utrrrongeeb
- Posts: 254
- Joined: 2006-05-14 09:48
- Location: Eastern Canada
Ok, it sounds like I didn't clarify it enough, so I'll elaborate:
I was thinking of writing a program that runs when you login to X. It runs in the background throughout your X session. Every second, it checks a text file for updates. If an update is present, it runs Zenity/dialog/xdialog/gdialog/cdialog/xmessage/gmessage with the recent appendations (probably not a word) to the file.
I was thinking of writing a program that runs when you login to X. It runs in the background throughout your X session. Every second, it checks a text file for updates. If an update is present, it runs Zenity/dialog/xdialog/gdialog/cdialog/xmessage/gmessage with the recent appendations (probably not a word) to the file.
utrrrongeeb formerly lecaro
Art #429775 on 'Etch' 4.0r0
Art #429775 on 'Etch' 4.0r0