Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

bash script local + remote server

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
sabrina
Posts: 2
Joined: 2018-12-14 12:42

bash script local + remote server

#1 Post by sabrina »

I need to check all directory for Server1 and create this directory from local server for Server2

The local server goes without a problem - download and create

Fragment

Code: Select all


if [[ $movedomain == "t" ]]; then 
  cd /home/$olduser/$old_domain/
  alldomainsuser=($(ls -d */))
for i in "${!alldomainsuser[@]}"
do
  echo " ${alldomainsuser[$i]}"
  mkdir -p /home/$newuser/${alldomains[$i]}
done
Its works.

I can not get a list of directories from the remote server. I tried using ssh @ remote.

xepan
Posts: 89
Joined: 2018-11-28 06:38

Re: bash script local + remote server

#2 Post by xepan »

Not that sure if it comes with drawbacks, but you can just ssh@remote <command>
Quick test this seems to work:

Code: Select all

$ v=($(ssh void-raspberry find Programming  -type d -maxdepth 1))
$ for i in "${v[@]}"; do printf "%s\n" "$i"; done
Programming
Programming/bash
Programming/notabug
$
https://shellcheck.net complains about that and proposes mapfile instead:

Code: Select all

$ mapfile -t v < <(ssh void-raspberry find Programming -maxdepth 1 -type d)
If it is a critical project, i would ask in #bash. As soon ssh is involved, it gets messy (as in: not hard to oversee something).

Looking at your fragment some comments (perhaps superfluous) which might not be correct, but are just usual/general statements (not for your specific case, which i don't fully understand :-) ) :
never ever parse ls http://mywiki.wooledge.org/ParsingLs
qefs: "$Quote" "$Every" "$******" "$Substitution"
if it was me i would exit as soon an mkdir gives an error (not sure about that one though).

Perhaps i misunderstood you. If so, sorry. Don't take my word for it anyway. Make sure to double- and even triplecheck, i might well be wrong.
Good luck.

sabrina
Posts: 2
Joined: 2018-12-14 12:42

Re: bash script local + remote server

#3 Post by sabrina »

Thanks :)

Post Reply