Want to create a script to grep a particular word from a specific path of remote server
Clash Royale CLAN TAG#URR8PPP
I want to create a script wherein I can grep a particular word from a specific path of remote server and display that whole grep sentence in the output.
Currently, I have to take access to the target server, then to go in the particular path and then use the grep command.
#!/usr/bin/ksh
clientID="00000"
print -n "nEnter the ID (Enter ybr for ybr_ybrfndt): $1"
read clientID
print "$clientID"
for HOST in $(cat qa_servers.txt ) ;
do
ssh $HOST "uname -a"
cd /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA
grep $clientID resources.xml;
done
shell-script
|
show 1 more comment
I want to create a script wherein I can grep a particular word from a specific path of remote server and display that whole grep sentence in the output.
Currently, I have to take access to the target server, then to go in the particular path and then use the grep command.
#!/usr/bin/ksh
clientID="00000"
print -n "nEnter the ID (Enter ybr for ybr_ybrfndt): $1"
read clientID
print "$clientID"
for HOST in $(cat qa_servers.txt ) ;
do
ssh $HOST "uname -a"
cd /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA
grep $clientID resources.xml;
done
shell-script
1
welcome to U&L, we are not a scripting services, what have you tried so far ? can you provide (by editing your question) some sample (environment , expected output) ?
– Archemar
Jan 29 at 9:51
#!/usr/bin/ksh for server in "$qa_servers.txt[@]"; ssh cacher@$server cd /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA untar archive clientID="00000" print -n "nEnter the client ID: $1" read clientID print "$clientID" grep '$clientID' resources.xml
– user334028
Jan 29 at 9:57
Put this information in the question, not in a comment.
– Panki
Jan 29 at 10:04
Your code is nonsensical. Thefor
loop does not have ado
and you are using variables (some of which are arrays) that you never set.
– Kusalananda
Jan 29 at 10:21
how about this #!/usr/bin/ksh clientID="00000" print -n "nEnter the ID (Enter ybr for ybr_ybrfndt): $1" read clientID print "$clientID" for HOST in $(cat qa_servers.txt ) ; do ssh $HOST "uname -a" cd /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA grep $clientID resources.xml; done
– user334028
Jan 29 at 10:41
|
show 1 more comment
I want to create a script wherein I can grep a particular word from a specific path of remote server and display that whole grep sentence in the output.
Currently, I have to take access to the target server, then to go in the particular path and then use the grep command.
#!/usr/bin/ksh
clientID="00000"
print -n "nEnter the ID (Enter ybr for ybr_ybrfndt): $1"
read clientID
print "$clientID"
for HOST in $(cat qa_servers.txt ) ;
do
ssh $HOST "uname -a"
cd /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA
grep $clientID resources.xml;
done
shell-script
I want to create a script wherein I can grep a particular word from a specific path of remote server and display that whole grep sentence in the output.
Currently, I have to take access to the target server, then to go in the particular path and then use the grep command.
#!/usr/bin/ksh
clientID="00000"
print -n "nEnter the ID (Enter ybr for ybr_ybrfndt): $1"
read clientID
print "$clientID"
for HOST in $(cat qa_servers.txt ) ;
do
ssh $HOST "uname -a"
cd /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA
grep $clientID resources.xml;
done
shell-script
shell-script
edited Jan 29 at 11:02
msp9011
4,33444065
4,33444065
asked Jan 29 at 9:47
user334028user334028
66
66
1
welcome to U&L, we are not a scripting services, what have you tried so far ? can you provide (by editing your question) some sample (environment , expected output) ?
– Archemar
Jan 29 at 9:51
#!/usr/bin/ksh for server in "$qa_servers.txt[@]"; ssh cacher@$server cd /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA untar archive clientID="00000" print -n "nEnter the client ID: $1" read clientID print "$clientID" grep '$clientID' resources.xml
– user334028
Jan 29 at 9:57
Put this information in the question, not in a comment.
– Panki
Jan 29 at 10:04
Your code is nonsensical. Thefor
loop does not have ado
and you are using variables (some of which are arrays) that you never set.
– Kusalananda
Jan 29 at 10:21
how about this #!/usr/bin/ksh clientID="00000" print -n "nEnter the ID (Enter ybr for ybr_ybrfndt): $1" read clientID print "$clientID" for HOST in $(cat qa_servers.txt ) ; do ssh $HOST "uname -a" cd /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA grep $clientID resources.xml; done
– user334028
Jan 29 at 10:41
|
show 1 more comment
1
welcome to U&L, we are not a scripting services, what have you tried so far ? can you provide (by editing your question) some sample (environment , expected output) ?
– Archemar
Jan 29 at 9:51
#!/usr/bin/ksh for server in "$qa_servers.txt[@]"; ssh cacher@$server cd /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA untar archive clientID="00000" print -n "nEnter the client ID: $1" read clientID print "$clientID" grep '$clientID' resources.xml
– user334028
Jan 29 at 9:57
Put this information in the question, not in a comment.
– Panki
Jan 29 at 10:04
Your code is nonsensical. Thefor
loop does not have ado
and you are using variables (some of which are arrays) that you never set.
– Kusalananda
Jan 29 at 10:21
how about this #!/usr/bin/ksh clientID="00000" print -n "nEnter the ID (Enter ybr for ybr_ybrfndt): $1" read clientID print "$clientID" for HOST in $(cat qa_servers.txt ) ; do ssh $HOST "uname -a" cd /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA grep $clientID resources.xml; done
– user334028
Jan 29 at 10:41
1
1
welcome to U&L, we are not a scripting services, what have you tried so far ? can you provide (by editing your question) some sample (environment , expected output) ?
– Archemar
Jan 29 at 9:51
welcome to U&L, we are not a scripting services, what have you tried so far ? can you provide (by editing your question) some sample (environment , expected output) ?
– Archemar
Jan 29 at 9:51
#!/usr/bin/ksh for server in "$qa_servers.txt[@]"; ssh cacher@$server cd /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA untar archive clientID="00000" print -n "nEnter the client ID: $1" read clientID print "$clientID" grep '$clientID' resources.xml
– user334028
Jan 29 at 9:57
#!/usr/bin/ksh for server in "$qa_servers.txt[@]"; ssh cacher@$server cd /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA untar archive clientID="00000" print -n "nEnter the client ID: $1" read clientID print "$clientID" grep '$clientID' resources.xml
– user334028
Jan 29 at 9:57
Put this information in the question, not in a comment.
– Panki
Jan 29 at 10:04
Put this information in the question, not in a comment.
– Panki
Jan 29 at 10:04
Your code is nonsensical. The
for
loop does not have a do
and you are using variables (some of which are arrays) that you never set.– Kusalananda
Jan 29 at 10:21
Your code is nonsensical. The
for
loop does not have a do
and you are using variables (some of which are arrays) that you never set.– Kusalananda
Jan 29 at 10:21
how about this #!/usr/bin/ksh clientID="00000" print -n "nEnter the ID (Enter ybr for ybr_ybrfndt): $1" read clientID print "$clientID" for HOST in $(cat qa_servers.txt ) ; do ssh $HOST "uname -a" cd /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA grep $clientID resources.xml; done
– user334028
Jan 29 at 10:41
how about this #!/usr/bin/ksh clientID="00000" print -n "nEnter the ID (Enter ybr for ybr_ybrfndt): $1" read clientID print "$clientID" for HOST in $(cat qa_servers.txt ) ; do ssh $HOST "uname -a" cd /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA grep $clientID resources.xml; done
– user334028
Jan 29 at 10:41
|
show 1 more comment
1 Answer
1
active
oldest
votes
This script should work for your use case.
#!/usr/bin/ksh
print -n "nEnter the ID (Enter ybr for ybr_ybrfndt):"
read clientID
while IFS= read -r host
do
ssh -n $host "uname -a; grep $clientID /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA/resources.xml;"
done < qa_servers.txt
yes it's working...thanks...but what if i want the same for multiple servers
– user334028
Jan 29 at 11:37
@user334028 There's awhile
loop here that reads from the 'qa_servers.txt' file, one line at a time. So thessh
command will be executed for each line in that file. Do you mean something else by 'multiple servers'?
– Haxiel
Jan 29 at 11:39
I just meant that if in the text file i enter the next server name in next line. Will it work ?
– user334028
Jan 29 at 11:59
@user334028 Yes, it will work. There are no destructive commands involved here, so feel free to experiment.
– Haxiel
Jan 29 at 12:06
nope....it's not working for more than one server
– user334028
Jan 29 at 12:10
|
show 9 more comments
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f497396%2fwant-to-create-a-script-to-grep-a-particular-word-from-a-specific-path-of-remote%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This script should work for your use case.
#!/usr/bin/ksh
print -n "nEnter the ID (Enter ybr for ybr_ybrfndt):"
read clientID
while IFS= read -r host
do
ssh -n $host "uname -a; grep $clientID /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA/resources.xml;"
done < qa_servers.txt
yes it's working...thanks...but what if i want the same for multiple servers
– user334028
Jan 29 at 11:37
@user334028 There's awhile
loop here that reads from the 'qa_servers.txt' file, one line at a time. So thessh
command will be executed for each line in that file. Do you mean something else by 'multiple servers'?
– Haxiel
Jan 29 at 11:39
I just meant that if in the text file i enter the next server name in next line. Will it work ?
– user334028
Jan 29 at 11:59
@user334028 Yes, it will work. There are no destructive commands involved here, so feel free to experiment.
– Haxiel
Jan 29 at 12:06
nope....it's not working for more than one server
– user334028
Jan 29 at 12:10
|
show 9 more comments
This script should work for your use case.
#!/usr/bin/ksh
print -n "nEnter the ID (Enter ybr for ybr_ybrfndt):"
read clientID
while IFS= read -r host
do
ssh -n $host "uname -a; grep $clientID /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA/resources.xml;"
done < qa_servers.txt
yes it's working...thanks...but what if i want the same for multiple servers
– user334028
Jan 29 at 11:37
@user334028 There's awhile
loop here that reads from the 'qa_servers.txt' file, one line at a time. So thessh
command will be executed for each line in that file. Do you mean something else by 'multiple servers'?
– Haxiel
Jan 29 at 11:39
I just meant that if in the text file i enter the next server name in next line. Will it work ?
– user334028
Jan 29 at 11:59
@user334028 Yes, it will work. There are no destructive commands involved here, so feel free to experiment.
– Haxiel
Jan 29 at 12:06
nope....it's not working for more than one server
– user334028
Jan 29 at 12:10
|
show 9 more comments
This script should work for your use case.
#!/usr/bin/ksh
print -n "nEnter the ID (Enter ybr for ybr_ybrfndt):"
read clientID
while IFS= read -r host
do
ssh -n $host "uname -a; grep $clientID /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA/resources.xml;"
done < qa_servers.txt
This script should work for your use case.
#!/usr/bin/ksh
print -n "nEnter the ID (Enter ybr for ybr_ybrfndt):"
read clientID
while IFS= read -r host
do
ssh -n $host "uname -a; grep $clientID /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA/resources.xml;"
done < qa_servers.txt
edited Jan 29 at 14:30
answered Jan 29 at 11:04
HaxielHaxiel
2,7401915
2,7401915
yes it's working...thanks...but what if i want the same for multiple servers
– user334028
Jan 29 at 11:37
@user334028 There's awhile
loop here that reads from the 'qa_servers.txt' file, one line at a time. So thessh
command will be executed for each line in that file. Do you mean something else by 'multiple servers'?
– Haxiel
Jan 29 at 11:39
I just meant that if in the text file i enter the next server name in next line. Will it work ?
– user334028
Jan 29 at 11:59
@user334028 Yes, it will work. There are no destructive commands involved here, so feel free to experiment.
– Haxiel
Jan 29 at 12:06
nope....it's not working for more than one server
– user334028
Jan 29 at 12:10
|
show 9 more comments
yes it's working...thanks...but what if i want the same for multiple servers
– user334028
Jan 29 at 11:37
@user334028 There's awhile
loop here that reads from the 'qa_servers.txt' file, one line at a time. So thessh
command will be executed for each line in that file. Do you mean something else by 'multiple servers'?
– Haxiel
Jan 29 at 11:39
I just meant that if in the text file i enter the next server name in next line. Will it work ?
– user334028
Jan 29 at 11:59
@user334028 Yes, it will work. There are no destructive commands involved here, so feel free to experiment.
– Haxiel
Jan 29 at 12:06
nope....it's not working for more than one server
– user334028
Jan 29 at 12:10
yes it's working...thanks...but what if i want the same for multiple servers
– user334028
Jan 29 at 11:37
yes it's working...thanks...but what if i want the same for multiple servers
– user334028
Jan 29 at 11:37
@user334028 There's a
while
loop here that reads from the 'qa_servers.txt' file, one line at a time. So the ssh
command will be executed for each line in that file. Do you mean something else by 'multiple servers'?– Haxiel
Jan 29 at 11:39
@user334028 There's a
while
loop here that reads from the 'qa_servers.txt' file, one line at a time. So the ssh
command will be executed for each line in that file. Do you mean something else by 'multiple servers'?– Haxiel
Jan 29 at 11:39
I just meant that if in the text file i enter the next server name in next line. Will it work ?
– user334028
Jan 29 at 11:59
I just meant that if in the text file i enter the next server name in next line. Will it work ?
– user334028
Jan 29 at 11:59
@user334028 Yes, it will work. There are no destructive commands involved here, so feel free to experiment.
– Haxiel
Jan 29 at 12:06
@user334028 Yes, it will work. There are no destructive commands involved here, so feel free to experiment.
– Haxiel
Jan 29 at 12:06
nope....it's not working for more than one server
– user334028
Jan 29 at 12:10
nope....it's not working for more than one server
– user334028
Jan 29 at 12:10
|
show 9 more comments
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f497396%2fwant-to-create-a-script-to-grep-a-particular-word-from-a-specific-path-of-remote%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
welcome to U&L, we are not a scripting services, what have you tried so far ? can you provide (by editing your question) some sample (environment , expected output) ?
– Archemar
Jan 29 at 9:51
#!/usr/bin/ksh for server in "$qa_servers.txt[@]"; ssh cacher@$server cd /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA untar archive clientID="00000" print -n "nEnter the client ID: $1" read clientID print "$clientID" grep '$clientID' resources.xml
– user334028
Jan 29 at 9:57
Put this information in the question, not in a comment.
– Panki
Jan 29 at 10:04
Your code is nonsensical. The
for
loop does not have ado
and you are using variables (some of which are arrays) that you never set.– Kusalananda
Jan 29 at 10:21
how about this #!/usr/bin/ksh clientID="00000" print -n "nEnter the ID (Enter ybr for ybr_ybrfndt): $1" read clientID print "$clientID" for HOST in $(cat qa_servers.txt ) ; do ssh $HOST "uname -a" cd /apps/WebSphere/NA70_TBA/config/cells/CellV70_TBA grep $clientID resources.xml; done
– user334028
Jan 29 at 10:41