Skip to main content
Commonmark migration
Source Link

I am trying to run a for loop which looks something like this

cat  all_data |
  awk '{print $1 " "$2" " $3}'  |
  while read inst type serial ; do
    echo $inst
    if [ `echo ${inst} | cut -d '-' -f2` = H3 ]; then
      ssh  -t  username@hostname3 "sudo ls"
    elif [ `echo ${inst} | cut -d '-' -f2` = H2 ] ; then
      ssh  -t  username@hostname2 "sudo ls"
    elif [ `echo ${inst} | cut -d '-' -f2` = H1 ]; then
      ssh  -t  username@hostname1 "sudo ls"
    fi
  done

I am not able to run the ssh -t part,it says psuedo terminal will not be allocated becasued stdin is not a terminal sudo: no tty present and no askpass program specified I have tried with -t -t and -n, no luck. I cant edit the visudo file from the host i am running this command from.

###Edit

Edit

$ cat all_data
ABC-DIF2    DELL-800    60999
ABC-DIF3    HP-DL340    J0777
ABC-DIF4    DELL-800    P0087
.
.
.

The all_data contains 1000's of the similar entries. What i am trying to do it as follows. 60999,J0777... are the entities on which i need to run commands on.

So i am trying to read each line, split up and check what is the DIF number corresponding to the entity.

eg If i read DIF2, it means that i need to ssh into hostname2 and run the command to get data on the 60999

If if i read DIF3, it means for the entity J0777 can only be run from hostname3.

I am trying to run a for loop which looks something like this

cat  all_data |
  awk '{print $1 " "$2" " $3}'  |
  while read inst type serial ; do
    echo $inst
    if [ `echo ${inst} | cut -d '-' -f2` = H3 ]; then
      ssh  -t  username@hostname3 "sudo ls"
    elif [ `echo ${inst} | cut -d '-' -f2` = H2 ] ; then
      ssh  -t  username@hostname2 "sudo ls"
    elif [ `echo ${inst} | cut -d '-' -f2` = H1 ]; then
      ssh  -t  username@hostname1 "sudo ls"
    fi
  done

I am not able to run the ssh -t part,it says psuedo terminal will not be allocated becasued stdin is not a terminal sudo: no tty present and no askpass program specified I have tried with -t -t and -n, no luck. I cant edit the visudo file from the host i am running this command from.

###Edit

$ cat all_data
ABC-DIF2    DELL-800    60999
ABC-DIF3    HP-DL340    J0777
ABC-DIF4    DELL-800    P0087
.
.
.

The all_data contains 1000's of the similar entries. What i am trying to do it as follows. 60999,J0777... are the entities on which i need to run commands on.

So i am trying to read each line, split up and check what is the DIF number corresponding to the entity.

eg If i read DIF2, it means that i need to ssh into hostname2 and run the command to get data on the 60999

If if i read DIF3, it means for the entity J0777 can only be run from hostname3.

I am trying to run a for loop which looks something like this

cat  all_data |
  awk '{print $1 " "$2" " $3}'  |
  while read inst type serial ; do
    echo $inst
    if [ `echo ${inst} | cut -d '-' -f2` = H3 ]; then
      ssh  -t  username@hostname3 "sudo ls"
    elif [ `echo ${inst} | cut -d '-' -f2` = H2 ] ; then
      ssh  -t  username@hostname2 "sudo ls"
    elif [ `echo ${inst} | cut -d '-' -f2` = H1 ]; then
      ssh  -t  username@hostname1 "sudo ls"
    fi
  done

I am not able to run the ssh -t part,it says psuedo terminal will not be allocated becasued stdin is not a terminal sudo: no tty present and no askpass program specified I have tried with -t -t and -n, no luck. I cant edit the visudo file from the host i am running this command from.

Edit

$ cat all_data
ABC-DIF2    DELL-800    60999
ABC-DIF3    HP-DL340    J0777
ABC-DIF4    DELL-800    P0087
.
.
.

The all_data contains 1000's of the similar entries. What i am trying to do it as follows. 60999,J0777... are the entities on which i need to run commands on.

So i am trying to read each line, split up and check what is the DIF number corresponding to the entity.

eg If i read DIF2, it means that i need to ssh into hostname2 and run the command to get data on the 60999

If if i read DIF3, it means for the entity J0777 can only be run from hostname3.

added 1 character in body
Source Link
coolguy6764
  • 81
  • 1
  • 2
  • 5

I am trying to run a for loop which looks something like this

cat  all_data |
  awk '{print $1 " "$2" " $3}'  |
  while read inst type serial ; do
    echo $inst
    if [ `echo ${inst} | cut -d '-' -f2` = H3 ]; then
      ssh  -t  username@hostname1username@hostname3 "sudo ls"
    elif [ `echo ${inst} | cut -d '-' -f2` = H2 ] ; then
      ssh  -t  username@hostname2 "sudo ls"
    elif [ `echo ${inst} | cut -d '-' -f2` = 1H1 ]; then
      ssh  -t  username@hostname1 "sudo ls"
    fi
  done

I am not able to run the ssh -t part,it says psuedo terminal will not be allocated becasued stdin is not a terminal sudo: no tty present and no askpass program specified I have tried with -t -t and -n, no luck. I cant edit the visudo file from the host i am running this command from.

###Edit

$ cat all_data
ABC-DIF2    DELL-800    60999
ABC-DIF3    HP-DL340    J0777
ABC-DIF4    DELL-800    P0087
.
.
.

The all_data contains 1000's of the similar entries. What i am trying to do it as follows. 60999,J0777... are the entities on which i need to run commands on.

So i am trying to read each line, split up and check what is the DIF number corresponding to the entity.

eg If i read DIF2, it means that i need to ssh into hostname2 and run the command to get data on the 60999

If if i read DIF3, it means for the entity J0777 can only be run from hostname3.

I am trying to run a for loop which looks something like this

cat  all_data |
  awk '{print $1 " "$2" " $3}'  |
  while read inst type serial ; do
    echo $inst
    if [ `echo ${inst} | cut -d '-' -f2` = H3 ]; then
      ssh  -t  username@hostname1 "sudo ls"
    elif [ `echo ${inst} | cut -d '-' -f2` = H2 ] ; then
      ssh  -t  username@hostname2 "sudo ls"
    elif [ `echo ${inst} | cut -d '-' -f2` = 1 ]; then
      ssh  -t  username@hostname1 "sudo ls"
    fi
  done

I am not able to run the ssh -t part,it says psuedo terminal will not be allocated becasued stdin is not a terminal sudo: no tty present and no askpass program specified I have tried with -t -t and -n, no luck. I cant edit the visudo file from the host i am running this command from.

###Edit

$ cat all_data
ABC-DIF2    DELL-800    60999
ABC-DIF3    HP-DL340    J0777
ABC-DIF4    DELL-800    P0087
.
.
.

The all_data contains 1000's of the similar entries. What i am trying to do it as follows. 60999,J0777... are the entities on which i need to run commands on.

So i am trying to read each line, split up and check what is the DIF number corresponding to the entity.

eg If i read DIF2, it means that i need to ssh into hostname2 and run the command to get data on the 60999

If if i read DIF3, it means for the entity J0777 can only be run from hostname3.

I am trying to run a for loop which looks something like this

cat  all_data |
  awk '{print $1 " "$2" " $3}'  |
  while read inst type serial ; do
    echo $inst
    if [ `echo ${inst} | cut -d '-' -f2` = H3 ]; then
      ssh  -t  username@hostname3 "sudo ls"
    elif [ `echo ${inst} | cut -d '-' -f2` = H2 ] ; then
      ssh  -t  username@hostname2 "sudo ls"
    elif [ `echo ${inst} | cut -d '-' -f2` = H1 ]; then
      ssh  -t  username@hostname1 "sudo ls"
    fi
  done

I am not able to run the ssh -t part,it says psuedo terminal will not be allocated becasued stdin is not a terminal sudo: no tty present and no askpass program specified I have tried with -t -t and -n, no luck. I cant edit the visudo file from the host i am running this command from.

###Edit

$ cat all_data
ABC-DIF2    DELL-800    60999
ABC-DIF3    HP-DL340    J0777
ABC-DIF4    DELL-800    P0087
.
.
.

The all_data contains 1000's of the similar entries. What i am trying to do it as follows. 60999,J0777... are the entities on which i need to run commands on.

So i am trying to read each line, split up and check what is the DIF number corresponding to the entity.

eg If i read DIF2, it means that i need to ssh into hostname2 and run the command to get data on the 60999

If if i read DIF3, it means for the entity J0777 can only be run from hostname3.

fixed formatting, removed chatter
Source Link
cas
  • 84.4k
  • 9
  • 136
  • 205

I am trying to run a for loop which looks something like this

cat  all_data |
  awk '{print $1 " "$2" " $3}'  |
  while read inst type serial ; do
    echo $inst
    if [ `echo ${inst} | cut -d '-' -f2` = H3 ]; then
      ssh  -t  username@hostname1 "sudo ls"
    elif [ `echo ${inst} | cut -d '-' -f2` = H2 ] ; then
      ssh  -t  username@hostname2 "sudo ls"
    elif [ `echo ${inst} | cut -d '-' -f2` = 1 ]; then
      ssh  -t  username@hostname1 "sudo ls"
    fi
  done

I am not able to run the ssh -t part,it says psuedo terminal will not be allocated becasued stdin is not a terminal sudo: no tty present and no askpass program specified I have tried with -t -t and -n, no luck. I cant edit the visudo file from the host i am running this command from.

###Edit cat all_data

ABC-DIF2 DELL-800 60999

ABC-DIF3 HP-DL340 J0777

ABC-DIF4 DELL-800 P0087 . . .

$ cat all_data
ABC-DIF2    DELL-800    60999
ABC-DIF3    HP-DL340    J0777
ABC-DIF4    DELL-800    P0087
.
.
.

The all_data contains 1000's of the similar entries. What i am trying to do it as follows. 60999,J0777... are the entities on which i need to run commands on.

So i am trying to read each line, split up and check what is the DIF number corresponding to the entity. eg

eg If i read DIF2, it means that i need to ssh into hostname2 and run the command to get data on the 60999 If

If if i read DIF3, it means for the entity J0777 can only be run from hostname3.

Can someone please help

I am trying to run a for loop which looks something like this

cat  all_data |
  awk '{print $1 " "$2" " $3}'  |
  while read inst type serial ; do
    echo $inst
    if [ `echo ${inst} | cut -d '-' -f2` = H3 ]; then
      ssh  -t  username@hostname1 "sudo ls"
    elif [ `echo ${inst} | cut -d '-' -f2` = H2 ] ; then
      ssh  -t  username@hostname2 "sudo ls"
    elif [ `echo ${inst} | cut -d '-' -f2` = 1 ]; then
      ssh  -t  username@hostname1 "sudo ls"
    fi
  done

I am not able to run the ssh -t part,it says psuedo terminal will not be allocated becasued stdin is not a terminal sudo: no tty present and no askpass program specified I have tried with -t -t and -n, no luck. I cant edit the visudo file from the host i am running this command from.

###Edit cat all_data

ABC-DIF2 DELL-800 60999

ABC-DIF3 HP-DL340 J0777

ABC-DIF4 DELL-800 P0087 . . .

The all_data contains 1000's of the similar entries. What i am trying to do it as follows. 60999,J0777... are the entities on which i need to run commands on.

So i am trying to read each line, split up and check what is the DIF number corresponding to the entity. eg If i read DIF2, it means that i need to ssh into hostname2 and run the command to get data on the 60999 If if i read DIF3, it means for the entity J0777 can only be run from hostname3.

Can someone please help

I am trying to run a for loop which looks something like this

cat  all_data |
  awk '{print $1 " "$2" " $3}'  |
  while read inst type serial ; do
    echo $inst
    if [ `echo ${inst} | cut -d '-' -f2` = H3 ]; then
      ssh  -t  username@hostname1 "sudo ls"
    elif [ `echo ${inst} | cut -d '-' -f2` = H2 ] ; then
      ssh  -t  username@hostname2 "sudo ls"
    elif [ `echo ${inst} | cut -d '-' -f2` = 1 ]; then
      ssh  -t  username@hostname1 "sudo ls"
    fi
  done

I am not able to run the ssh -t part,it says psuedo terminal will not be allocated becasued stdin is not a terminal sudo: no tty present and no askpass program specified I have tried with -t -t and -n, no luck. I cant edit the visudo file from the host i am running this command from.

###Edit

$ cat all_data
ABC-DIF2    DELL-800    60999
ABC-DIF3    HP-DL340    J0777
ABC-DIF4    DELL-800    P0087
.
.
.

The all_data contains 1000's of the similar entries. What i am trying to do it as follows. 60999,J0777... are the entities on which i need to run commands on.

So i am trying to read each line, split up and check what is the DIF number corresponding to the entity.

eg If i read DIF2, it means that i need to ssh into hostname2 and run the command to get data on the 60999

If if i read DIF3, it means for the entity J0777 can only be run from hostname3.

added 576 characters in body
Source Link
coolguy6764
  • 81
  • 1
  • 2
  • 5
Loading
made script readable
Source Link
cas
  • 84.4k
  • 9
  • 136
  • 205
Loading
Source Link
coolguy6764
  • 81
  • 1
  • 2
  • 5
Loading