LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-11-2022, 11:07 PM   #16
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,879
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871

Maybe another example will help:
Code:
for i in pavel@devel1 pedro@qa admin@product1 admin@product2; do
    echo "=== $i ==="
    ssh "$i" 'find / -type f -name temp.txt' </dev/null
done
 
Old 06-12-2022, 06:10 AM   #17
1s440
Member
 
Registered: Mar 2018
Posts: 266

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
Maybe another example will help:
Code:
for i in pavel@devel1 pedro@qa admin@product1 admin@product2; do
    echo "=== $i ==="
    ssh "$i" 'find / -type f -name temp.txt' </dev/null
done
Code:
user@server:~$ su - s1
ssh server
[s1@ts1/server ~]$ switchuser
switchuser@server ----------->
this is how we connect and from swichuser@server.. there are temp.txt files under /app/tmp/

in the sameway: we have many users say s2, s3, s4...

for ex: to find second temp.txt on s2, but this is manual..

Code:
user@server:~$ su - s2 
ssh server (ssh instance)
[s2@ts1/server ~]$ switchuser 
switchuser@server ----------->
 
Old 06-12-2022, 10:47 AM   #18
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,879
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
I cannot help but noticing you keep adding bits to your problem instead of describing every details once.
You can use su -c on local or remote side. Or both. E.g.
Code:
su localuser2 -c "ssh -t remoteuser1@host \"su remoteuser2 -c \\\"find /tmp -name temp.txt -type f\\\"\""
Note: I didn't created this manually, it was a script:
Code:
quote() {
    printf '"%s"' "$(sed 's/[\\"]/\\&/g' <<<"$1")"
}

CMD1='find /tmp -name temp.txt -type f'
CMD2='su remoteuser2 -c '$(quote "$CMD1")
CMD3='ssh -t remoteuser1@host '$(quote "$CMD2")
CMD4='su localuser2 -c '$(quote "$CMD3")
set | grep CMD
 
Old 06-12-2022, 02:54 PM   #19
1s440
Member
 
Registered: Mar 2018
Posts: 266

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
I cannot help but noticing you keep adding bits to your problem instead of describing every details once.
You can use su -c on local or remote side. Or both. E.g.
Code:
su localuser2 -c "ssh -t remoteuser1@host \"su remoteuser2 -c \\\"find /tmp -name temp.txt -type f\\\"\""
Note: I didn't created this manually, it was a script:
Code:
quote() {
    printf '"%s"' "$(sed 's/[\\"]/\\&/g' <<<"$1")"
}

CMD1='find /tmp -name temp.txt -type f'
CMD2='su remoteuser2 -c '$(quote "$CMD1")
CMD3='ssh -t remoteuser1@host '$(quote "$CMD2")
CMD4='su localuser2 -c '$(quote "$CMD3")
set | grep CMD
Thank you so much. I will try
 
Old 06-12-2022, 05:26 PM   #20
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
Quote:
Originally Posted by NevemTeve View Post
I cannot help but noticing you keep adding bits to your problem instead of describing every details once.
@1s440: Indeed. It would be helpful for everyone, especially yourself, if you could take the time to write up minimal but a complete description of what you are trying to accomplish which includes all relevant constraints and goals. Please remember that those willing to offer help here are volunteering their time to help solve your problem. Help them help you and show respect for their kindness by helping them to understand the problem as clearly and quickly as possible.

You may find it helpful to review the Site FAQ for guidance in asking well formed questions. Especially visit the link from that page, How to Ask Questions the Smart Way for discussion of things to consider when asking others for help.

Good luck!

Last edited by astrogeek; 06-12-2022 at 05:27 PM.
 
Old 06-13-2022, 04:45 AM   #21
1s440
Member
 
Registered: Mar 2018
Posts: 266

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
@1s440: Indeed. It would be helpful for everyone, especially yourself, if you could take the time to write up minimal but a complete description of what you are trying to accomplish which includes all relevant constraints and goals. Please remember that those willing to offer help here are volunteering their time to help solve your problem. Help them help you and show respect for their kindness by helping them to understand the problem as clearly and quickly as possible.

You may find it helpful to review the Site FAQ for guidance in asking well formed questions. Especially visit the link from that page, How to Ask Questions the Smart Way for discussion of things to consider when asking others for help.

Good luck!
so i will put it in simple. I would need a find command to look for the temp.text in /app and its subdirectories and read the content
and present collectively.

Last edited by 1s440; 06-13-2022 at 04:55 AM.
 
Old 06-13-2022, 05:07 AM   #22
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Quote:
Originally Posted by 1s440 View Post
so i will put it in simple. I would need a find command to look for the temp.text in /app and its subdirectories and read the content
and present collectively.
Code:
find /app -name temp.txt -exec cat {} +
Weird to have a directory called "/app" though.

Evo2.

Last edited by evo2; 06-13-2022 at 05:09 AM.
 
Old 06-13-2022, 05:21 AM   #23
1s440
Member
 
Registered: Mar 2018
Posts: 266

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by evo2 View Post
Code:
find /app -name temp.txt -exec cat {} +
Weird to have a directory called "/app" though.

Evo2.
i have tried something like this but i have a problem in displaying its conents for ex:

Code:
find /app -name '*versions.txt' -print -exec cat {} +  > files.list
it displays
Code:
/app/tmp/folder/temp.txt
/app/oracle/scp/temp.txt
and then the output of the temp.txt later

it would be good if we get output

/app/tmp/folder/temp.txt

output

/app/oracle/scp/temp.txt

output

Last edited by 1s440; 06-13-2022 at 05:22 AM.
 
Old 06-13-2022, 05:50 AM   #24
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Quote:
Originally Posted by 1s440 View Post
i have tried something like this but i have a problem in displaying its conents for ex:

Code:
find /app -name '*versions.txt' -print -exec cat {} +  > files.list
Why are you adding the "-print" option?
Quote:
Originally Posted by 1s440 View Post
/app/tmp/folder/temp.txt

output

/app/oracle/scp/temp.txt

output
That's not what you asked in #21.

Evo2.

Last edited by evo2; 06-13-2022 at 05:52 AM.
 
Old 06-13-2022, 05:55 AM   #25
1s440
Member
 
Registered: Mar 2018
Posts: 266

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by evo2 View Post
Why are you adding the "-print" option?

That's not what you asked in #21.

Evo2.
tp present the output clearly..
 
Old 06-13-2022, 06:49 AM   #26
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,879
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
Nothing is clear so far as you keep moving the target.
Here is something you might think of:
Code:
find /path -name whatnot -type -print |
while read Name; do echo "=== $Name ==="; cat -- "$Name"; done
 
Old 06-13-2022, 07:32 AM   #27
1s440
Member
 
Registered: Mar 2018
Posts: 266

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
Nothing is clear so far as you keep moving the target.
Here is something you might think of:
Code:
find /path -name whatnot -type -print |
while read Name; do echo "=== $Name ==="; cat -- "$Name"; done
I am not sure how can i explain in betterway:

Code:
find /app -name '*temp.txt' -print -exec cat {} +  > files.list
you get output

Code:
/app/tmp/folder/temp.txt
/app/oracle/scp/temp.txt

--- ouput of temp.txt file

--- ouput of temp.txt file
is there a way that we get output of each txt files for ex: to be readable easily
Code:
/app/tmp/folder/temp.txt

--- ouput of txt file
/app/oracle/scp/temp.txt

--- ouput of txt file
 
Old 06-13-2022, 07:49 AM   #28
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,879
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
Here is an idea you might find familiar from earlier:
Code:
find /app -name '*temp.txt' -type f |\
while read Name; do echo "=== $Name ==="; cat -- "$Name"; done
 
Old 06-13-2022, 07:51 AM   #29
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,625

Rep: Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556

When multiple files are passed to tail, it precedes their outputs with the filename (between "==> " and " <==" ).

If the files are longer than 10 lines long, the -n option accepts +1 to mean "start from line one", and thus can be used to output everything.

In other words, replace "cat" with "tail -n+1" and remove the print.


Last edited by boughtonp; 06-13-2022 at 07:53 AM.
 
Old 06-13-2022, 07:53 AM   #30
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,026

Rep: Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343
Quote:
Originally Posted by NevemTeve View Post
Here is an idea you might find familiar from earlier:
Code:
find /app -name '*temp.txt' -type f |\
while read Name; do echo "=== $Name ==="; cat -- "$Name"; done
and you will get the next request.....
What I can suggest to the OP:
Code:
find /app -name '*temp.txt' -type f -exec <my_shell_script> {} \;
# and my shell script:
echo "$1"
cat "$1"
# or modify if you wish something else
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash Issue with Find Script: find paths must precede expression: *.txt JockVSJock Programming 4 01-06-2014 09:03 PM
Bash problem : -bash: [: /bin/bash: unary operator expected J.A.X Linux - Software 1 09-22-2011 05:52 AM
bash my little bash alaios Linux - Newbie 4 01-10-2005 11:59 PM
bash + html + javascript or just bash ? rblampain Programming 4 12-01-2004 07:53 AM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 06:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration