Piping output from a command into bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Piping output from a command into bash script
# 1  
Old 08-31-2010
Piping output from a command into bash script

Hi all. I am using procmail to deliver an email to a script I am developing. Procmail delivers the email to the script on standard input. I imagine this is the same as piping input from a command into the script. Hence I've been testing my script by running
echo 'test' | sms-autosend-backup.sh

I would expect the script to echo out the input passed to it, but this does not happen, I just get a blank line. My question is, how do I store standard input in a variable in my script? Is $1 not correct? Script is below. Thanks!

Code:
#!/bin/bash -norc

message=$1
echo $message

My .procmailrc looks like this:

Code:
VERBOSE=off
HOME=/home/sms-dev
MAILDIR=/var/spool/mail/sms-dev
LOGFILE=$HOME/procmail.log
SH=/bin/sh
PATH=/bin:/usr/bin:/usr/local/bin

:0
* ^TOsms-dev@sms.sms.local
{
:0c
| /home/sms-dev/sms-autosend.sh
:0
/var/spool/mail/sms-dev
:0
/home/sms-dev/mboxtest
}

# 2  
Old 08-31-2010
are you passing test as a $1 to your script sms-autosent-backup.sh if yes then you should be executing the script like ---------

Code:
sms-autosend-backup.sh  test

# 3  
Old 09-01-2010
$1 is the 1st arg of command line of script invocation.
Try using bash's read command since it is input.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Piping the "script" command through the logger command.

I use the snippet below in /etc/profile on RHEL Linux to capture command line logging and it all works well and good. Now I'd like to pipe the same output from script through the logger command so it all gets logged to syslog. The only additional code I've added is in bold below (|... (4 Replies)
Discussion started by: woodson2
4 Replies

2. Shell Programming and Scripting

Abnormality while piping tr command output to sed

i have a file seperated each line seperated by newline. For example alpha beta gamma i am trying to replace the newlines to "," but dont want , present at the end of the line so i am trying the below one liner . but not sure whats wrong but its not working cat myfile | tr -s '\n' ',' | sed... (9 Replies)
Discussion started by: chidori
9 Replies

3. Shell Programming and Scripting

In bash script, how to assign output of a command to a variable while keeping tabs?

Hi, wondering if it's been asked before but didn't find matches from google. Basically I have this line: myvar=$(echo -e "a\tb") Now somehow the '\t' from the echo output gets replaced with white space and then stored in $myvar. It creates a problem for me later to use tab as delimiter to do... (2 Replies)
Discussion started by: birddie
2 Replies

4. UNIX for Dummies Questions & Answers

How do i tell my bash shell script to test the output of a command against something

How do i tell my bash shell script to test the output of the command i'm using?? I want this script to look for lines not equal to 1 then let me know.. $ cat blah ; echo ---- ; cat blah.sh 1 fe 1 fi 1 fo 0 fum 1 blahda 1 blah 0 blahh 1 bla 1 bl 1 blahhh ---- #!/bin/bash while... (1 Reply)
Discussion started by: phpfreak
1 Replies

5. Shell Programming and Scripting

Piping from BASH in to an Instant Messenger??

Is it possible to pipe a command in to an instant messenger e.g pidgin, finch or something similar and have it send??? e.g echo "hello" | messenger Or is there anything similar?? Thanks in advance! (1 Reply)
Discussion started by: 64mb
1 Replies

6. Shell Programming and Scripting

KSH script: piping passes command-line arguments

Dear forum I have the following small script: #!/bin/ksh echo -e "abba-o" | awk -F '-' '{ print $2 }' | cut -b 1It needs to be ksh.. in bash I don't have this problem. If I run this on opensuse 10.2 I get this as output: e If I run this on suse enterprise 10 sp2 then I get this: o ... (1 Reply)
Discussion started by: gemtry
1 Replies

7. Shell Programming and Scripting

bash shell piping

Hello all, I am new to bash. I am trying to get a sub string of a variable in a shell script. While trying to do that I get the following error: ------------------------------------------------------------------------ OHOME: /aaa/bbb/product/eee ./t.sh: line 6: /aaa/bbb/product/eee: No... (4 Replies)
Discussion started by: RockyC123
4 Replies

8. Shell Programming and Scripting

piping output to echo

Hi, I was wondering why ls * | echo does not print the contents of the directory to the screen? The way I see it, ls * returns a whole lot of information, and then we pipe all this info to echo, so surely it should all come to our screen! Is there a serious flaw in my understanding? ... (3 Replies)
Discussion started by: A1977
3 Replies

9. UNIX for Dummies Questions & Answers

piping the output of find command to grep

Hi, I did not understand why the following did not work out as I expected: find . -name "pqp.txt" | grep -v "Permission" I thought I would be able to catch whichever paths containing my pqp.txt file without receiving the display of messages such as "find: cannot access... Permisson... (1 Reply)
Discussion started by: 435 Gavea
1 Replies

10. Shell Programming and Scripting

Piping output to while read

Hi. Im using cat to output the contents of a file, then piping it to my while read loop.In this loop variables get assigned values. However when i try to use the variables outside the loop their values has been reset.I understand about subshells etc. but I have no idea how to "preserve" the... (3 Replies)
Discussion started by: Ultimodiablo
3 Replies
Login or Register to Ask a Question