Fix pipe command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Fix pipe command
# 1  
Old 09-12-2013
Fix pipe command

Trying to get the below command to work which it does, however each time, regardless of host being up or not it always loops back to the start of the function where I need it to stop if the host is up and continue with teh rest of teh function.

Code:
echo -ne "Remote/local host address. Example user@192.168.0.10: "
read remote_host_addr
sudo ping -c1 $remote_host_addr > /dev/null && echo "Host is up" && sleep 1 || echo "$RED Host not reachable$STAND" && sleep 2 && ssh_func_send

# 2  
Old 09-13-2013
use actual if/then/else rather than trying to be cool with && and || shortcuts:

Code:
printf 'Remote/local host address. Example user@192.168.0.10: '
read remote_host_addr
if sudo ping -c1 "$remote_host_addr" > /dev/null; then
  echo "Host is up"
  sleep 1
else
  echo "$RED Host not reachable$STAND"
  sleep 2
  ssh_func_send
fi

# 3  
Old 09-13-2013
Worked perfectly, thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Would pipe work better with this command

Hi again, have a script that I would like run, but before I can run it I need to strip out the windows \r end of lines. I have put the command into a text file and set the command to run every 10 seconds the coomand I use to do this is while sleep 10; do... (15 Replies)
Discussion started by: Paul Walker
15 Replies

2. Shell Programming and Scripting

Pipe command to script

Hello to all, Having a ruby script that works when an argument is given in command line in this way: ruby script.rb input_to_ruby To accept arguments as input, inside the ruby script has File.open(ARGV) input_to_ruby is generated by another command, so I need to create first input_to_ruby... (6 Replies)
Discussion started by: Ophiuchus
6 Replies

3. Shell Programming and Scripting

pipe in command

Hello, I try to concatenate a command to execute. Sadly it throws an error. #!/bin/bash cd / cmd="find -name *.txt | awk '{ printf "FILE: "$1; system("less "$1);}' | egrep 'FILE:|$1'" echo "1." $($cmd) echo "2." $("$cmd") echo "3." `$cmd` echo "4." `"$cmd"`1.&3. 'find: paths must... (2 Replies)
Discussion started by: daWonderer
2 Replies

4. UNIX for Dummies Questions & Answers

is there any way of using rm command on output of pipe

Hi, I am having a list of directories with different login id's. My requirement is that i need to list the directories of my id and need to delete them. So i am using following code ls -ltr ¦ grep userid ¦ rm -rf But this is not working. So is there any way of doing it. Please note... (3 Replies)
Discussion started by: sarbjit
3 Replies

5. Shell Programming and Scripting

pipe command for array

Hi Folks, very basic question, how to do command piping for an array? suppose i have names as an array, when I write this script: #!/usr/bin/sh date=`date +%y%m%d`; names="a b" for name in ${names} do extract -tz +8 person 'income$|expense$' /home/ricki/$name/$date*.xml | tab -d -cols... (1 Reply)
Discussion started by: rickirick
1 Replies

6. UNIX for Advanced & Expert Users

unix command pipe

I am pretty new to UNIX. My client has a requirement where in a directory we have some files with somewhat similar name like test_XX.txt, test_XY.txt, test_XZ.txt, test_ZZ.txt, test_ZY.txt, test_ZX.txt, test_YY.txt......Out of these files few files have 0 bytes. Is there a way where we can go... (7 Replies)
Discussion started by: RubinPat
7 Replies

7. UNIX for Dummies Questions & Answers

Pipe in command string

Hi, Can't you have a pipe in a command string ? If I try the following I get errors. Why ? > cmd="ls -lrt | grep xyz" > $cmd |: No such file or directory grep: No such file or directory xyx: No such file or directory Thanks in advance Hench (3 Replies)
Discussion started by: hench
3 Replies

8. UNIX for Dummies Questions & Answers

How can I use pipe command ?

Hi My friends I have used this command to find files are modified within the past 24 hours and then many files are shown but I want transfer all these files to special directory by using pipe . can any one tell me what is the next step ? (11 Replies)
Discussion started by: bintaleb
11 Replies

9. UNIX for Dummies Questions & Answers

pipe command

current dir : /home/sales ls -l abc.txt 17th aug bcd .txt 16t oct ------- ------ Total files : 100 if i want to move only those files dated 17 aug into another sub directory /home/sales/texas how do i pipe the result of 'ls' command to a 'mv' command (1 Reply)
Discussion started by: zomboo
1 Replies

10. UNIX for Advanced & Expert Users

How to pipe command

Hi All, I want to create a command that executes a text editor with the most recent file in the current current directory. So a good start to achieve this is : ls -lrt | cut -c55- | tail -1 which provides the name of the most recent file in a directory The problem is to pipe the... (4 Replies)
Discussion started by: anonymous.nico
4 Replies
Login or Register to Ask a Question