grep exact string over ssh with variables [closed]
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I am trying to execute a script which grep the mount from fstab. when script is executed it gives multiple mounts matching the words instead of exact word matching.
#!/bin/bash
FNAME=$1
NFSSERVER=$2
NFSSHARE=$3
FILEPATH=/home/kumar/files
[ $# -ne 3 ] && echo "Usage: ./$0 FILENAME NFSSHARE NFSSERVER "; exit 1;
for I in `cat $FILEPATH/$FNAME|tr ":" "n"`
do
echo | tee -a $FILEPATH/$NFSSERVER-$NFSSHARE-fstab.txt
echo -e "$I ~ c" | tee -a $FILEPATH/$NFSSERVER-$NFSSHARE-fstab.txt
sshpass -f $FILEPATH/.pass ssh -q $I "grep -w $NFSSHARE /etc/fstab | grep -i $NFSSERVER" | tee -a $FILEPATH/$NFSSERVER-$NFSSHARE-fstab.txt
done
If I search for "apps_stage" NFSSHARE then the output comes for apps_stage, apps_stage_new, apps_stage_log. But the expected output is only for apps_stage.
The above script gives below output
nfs-1:/apps_stage /apps nfs _netdev,nolock,rsize=1048600,wsize=1048600 0 0
nfs-1:/apps_stage_new /apps/new nfs _netdev,nolock,rsize=1048600,wsize=1048600 0 0
nfs-1:/apps_stage_log /apps/log nfs _netdev,nolock,rsize=1048600,wsize=1048600 0 0
Expected output is only one line below
nfs-1:/apps_stage /apps nfs _netdev,nolock,rsize=1048600,wsize=1048600 0 0
When I run the same as a command in shell it works perfectly right.
NFSSHARE=apps_stage
NFSSERVER=nfs-1
I=testserver-1
sshpass -f ./files/.pass ssh -q $I "grep -w $NFSSHARE /etc/fstab | grep -i $NFSSERVER"
The above command gives me the exact required output as below.
nfs-1:/apps_stage /apps nfs _netdev,nolock,rsize=1048600,wsize=1048600 0 0
Not sure why it's not working in a script and working in the shell. Request you to guide me to make it work in a script.
Regards,
KJ.
ssh grep scripting variable fstab
closed as unclear what you're asking by Scott, JigglyNaga, Isaac, DarkHeart, X Tian Nov 28 at 14:34
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
0
down vote
favorite
I am trying to execute a script which grep the mount from fstab. when script is executed it gives multiple mounts matching the words instead of exact word matching.
#!/bin/bash
FNAME=$1
NFSSERVER=$2
NFSSHARE=$3
FILEPATH=/home/kumar/files
[ $# -ne 3 ] && echo "Usage: ./$0 FILENAME NFSSHARE NFSSERVER "; exit 1;
for I in `cat $FILEPATH/$FNAME|tr ":" "n"`
do
echo | tee -a $FILEPATH/$NFSSERVER-$NFSSHARE-fstab.txt
echo -e "$I ~ c" | tee -a $FILEPATH/$NFSSERVER-$NFSSHARE-fstab.txt
sshpass -f $FILEPATH/.pass ssh -q $I "grep -w $NFSSHARE /etc/fstab | grep -i $NFSSERVER" | tee -a $FILEPATH/$NFSSERVER-$NFSSHARE-fstab.txt
done
If I search for "apps_stage" NFSSHARE then the output comes for apps_stage, apps_stage_new, apps_stage_log. But the expected output is only for apps_stage.
The above script gives below output
nfs-1:/apps_stage /apps nfs _netdev,nolock,rsize=1048600,wsize=1048600 0 0
nfs-1:/apps_stage_new /apps/new nfs _netdev,nolock,rsize=1048600,wsize=1048600 0 0
nfs-1:/apps_stage_log /apps/log nfs _netdev,nolock,rsize=1048600,wsize=1048600 0 0
Expected output is only one line below
nfs-1:/apps_stage /apps nfs _netdev,nolock,rsize=1048600,wsize=1048600 0 0
When I run the same as a command in shell it works perfectly right.
NFSSHARE=apps_stage
NFSSERVER=nfs-1
I=testserver-1
sshpass -f ./files/.pass ssh -q $I "grep -w $NFSSHARE /etc/fstab | grep -i $NFSSERVER"
The above command gives me the exact required output as below.
nfs-1:/apps_stage /apps nfs _netdev,nolock,rsize=1048600,wsize=1048600 0 0
Not sure why it's not working in a script and working in the shell. Request you to guide me to make it work in a script.
Regards,
KJ.
ssh grep scripting variable fstab
closed as unclear what you're asking by Scott, JigglyNaga, Isaac, DarkHeart, X Tian Nov 28 at 14:34
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
Please edit the question to show the output of the failing script, rather than just describing it.
– JigglyNaga
Nov 27 at 13:53
Your standalone command contains some extra quotemarks that aren't in your script/loop -- what happens if you include those?
– JigglyNaga
Nov 27 at 13:54
Please learn to"$quote"
your"$variables"
.
– roaima
Nov 27 at 23:32
@JigglyNaga, thanks for the suggestion, edited the question accordingly. I have tried the same with quotes as well still the same issue.
– KumarJohn
Nov 28 at 6:55
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to execute a script which grep the mount from fstab. when script is executed it gives multiple mounts matching the words instead of exact word matching.
#!/bin/bash
FNAME=$1
NFSSERVER=$2
NFSSHARE=$3
FILEPATH=/home/kumar/files
[ $# -ne 3 ] && echo "Usage: ./$0 FILENAME NFSSHARE NFSSERVER "; exit 1;
for I in `cat $FILEPATH/$FNAME|tr ":" "n"`
do
echo | tee -a $FILEPATH/$NFSSERVER-$NFSSHARE-fstab.txt
echo -e "$I ~ c" | tee -a $FILEPATH/$NFSSERVER-$NFSSHARE-fstab.txt
sshpass -f $FILEPATH/.pass ssh -q $I "grep -w $NFSSHARE /etc/fstab | grep -i $NFSSERVER" | tee -a $FILEPATH/$NFSSERVER-$NFSSHARE-fstab.txt
done
If I search for "apps_stage" NFSSHARE then the output comes for apps_stage, apps_stage_new, apps_stage_log. But the expected output is only for apps_stage.
The above script gives below output
nfs-1:/apps_stage /apps nfs _netdev,nolock,rsize=1048600,wsize=1048600 0 0
nfs-1:/apps_stage_new /apps/new nfs _netdev,nolock,rsize=1048600,wsize=1048600 0 0
nfs-1:/apps_stage_log /apps/log nfs _netdev,nolock,rsize=1048600,wsize=1048600 0 0
Expected output is only one line below
nfs-1:/apps_stage /apps nfs _netdev,nolock,rsize=1048600,wsize=1048600 0 0
When I run the same as a command in shell it works perfectly right.
NFSSHARE=apps_stage
NFSSERVER=nfs-1
I=testserver-1
sshpass -f ./files/.pass ssh -q $I "grep -w $NFSSHARE /etc/fstab | grep -i $NFSSERVER"
The above command gives me the exact required output as below.
nfs-1:/apps_stage /apps nfs _netdev,nolock,rsize=1048600,wsize=1048600 0 0
Not sure why it's not working in a script and working in the shell. Request you to guide me to make it work in a script.
Regards,
KJ.
ssh grep scripting variable fstab
I am trying to execute a script which grep the mount from fstab. when script is executed it gives multiple mounts matching the words instead of exact word matching.
#!/bin/bash
FNAME=$1
NFSSERVER=$2
NFSSHARE=$3
FILEPATH=/home/kumar/files
[ $# -ne 3 ] && echo "Usage: ./$0 FILENAME NFSSHARE NFSSERVER "; exit 1;
for I in `cat $FILEPATH/$FNAME|tr ":" "n"`
do
echo | tee -a $FILEPATH/$NFSSERVER-$NFSSHARE-fstab.txt
echo -e "$I ~ c" | tee -a $FILEPATH/$NFSSERVER-$NFSSHARE-fstab.txt
sshpass -f $FILEPATH/.pass ssh -q $I "grep -w $NFSSHARE /etc/fstab | grep -i $NFSSERVER" | tee -a $FILEPATH/$NFSSERVER-$NFSSHARE-fstab.txt
done
If I search for "apps_stage" NFSSHARE then the output comes for apps_stage, apps_stage_new, apps_stage_log. But the expected output is only for apps_stage.
The above script gives below output
nfs-1:/apps_stage /apps nfs _netdev,nolock,rsize=1048600,wsize=1048600 0 0
nfs-1:/apps_stage_new /apps/new nfs _netdev,nolock,rsize=1048600,wsize=1048600 0 0
nfs-1:/apps_stage_log /apps/log nfs _netdev,nolock,rsize=1048600,wsize=1048600 0 0
Expected output is only one line below
nfs-1:/apps_stage /apps nfs _netdev,nolock,rsize=1048600,wsize=1048600 0 0
When I run the same as a command in shell it works perfectly right.
NFSSHARE=apps_stage
NFSSERVER=nfs-1
I=testserver-1
sshpass -f ./files/.pass ssh -q $I "grep -w $NFSSHARE /etc/fstab | grep -i $NFSSERVER"
The above command gives me the exact required output as below.
nfs-1:/apps_stage /apps nfs _netdev,nolock,rsize=1048600,wsize=1048600 0 0
Not sure why it's not working in a script and working in the shell. Request you to guide me to make it work in a script.
Regards,
KJ.
ssh grep scripting variable fstab
ssh grep scripting variable fstab
edited Nov 28 at 6:53
asked Nov 27 at 3:17
KumarJohn
11
11
closed as unclear what you're asking by Scott, JigglyNaga, Isaac, DarkHeart, X Tian Nov 28 at 14:34
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by Scott, JigglyNaga, Isaac, DarkHeart, X Tian Nov 28 at 14:34
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
Please edit the question to show the output of the failing script, rather than just describing it.
– JigglyNaga
Nov 27 at 13:53
Your standalone command contains some extra quotemarks that aren't in your script/loop -- what happens if you include those?
– JigglyNaga
Nov 27 at 13:54
Please learn to"$quote"
your"$variables"
.
– roaima
Nov 27 at 23:32
@JigglyNaga, thanks for the suggestion, edited the question accordingly. I have tried the same with quotes as well still the same issue.
– KumarJohn
Nov 28 at 6:55
add a comment |
Please edit the question to show the output of the failing script, rather than just describing it.
– JigglyNaga
Nov 27 at 13:53
Your standalone command contains some extra quotemarks that aren't in your script/loop -- what happens if you include those?
– JigglyNaga
Nov 27 at 13:54
Please learn to"$quote"
your"$variables"
.
– roaima
Nov 27 at 23:32
@JigglyNaga, thanks for the suggestion, edited the question accordingly. I have tried the same with quotes as well still the same issue.
– KumarJohn
Nov 28 at 6:55
Please edit the question to show the output of the failing script, rather than just describing it.
– JigglyNaga
Nov 27 at 13:53
Please edit the question to show the output of the failing script, rather than just describing it.
– JigglyNaga
Nov 27 at 13:53
Your standalone command contains some extra quotemarks that aren't in your script/loop -- what happens if you include those?
– JigglyNaga
Nov 27 at 13:54
Your standalone command contains some extra quotemarks that aren't in your script/loop -- what happens if you include those?
– JigglyNaga
Nov 27 at 13:54
Please learn to
"$quote"
your "$variables"
.– roaima
Nov 27 at 23:32
Please learn to
"$quote"
your "$variables"
.– roaima
Nov 27 at 23:32
@JigglyNaga, thanks for the suggestion, edited the question accordingly. I have tried the same with quotes as well still the same issue.
– KumarJohn
Nov 28 at 6:55
@JigglyNaga, thanks for the suggestion, edited the question accordingly. I have tried the same with quotes as well still the same issue.
– KumarJohn
Nov 28 at 6:55
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Please edit the question to show the output of the failing script, rather than just describing it.
– JigglyNaga
Nov 27 at 13:53
Your standalone command contains some extra quotemarks that aren't in your script/loop -- what happens if you include those?
– JigglyNaga
Nov 27 at 13:54
Please learn to
"$quote"
your"$variables"
.– roaima
Nov 27 at 23:32
@JigglyNaga, thanks for the suggestion, edited the question accordingly. I have tried the same with quotes as well still the same issue.
– KumarJohn
Nov 28 at 6:55