bash script local + remote server

Need help with C, C++, perl, python, etc?

bash script local + remote server

Postby sabrina » 2018-12-14 13:19

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

Code: Select all

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

Its works.

I can not get a list of directories from the remote server. I tried using ssh @ remote.
Posts: 2
Joined: 2018-12-14 12:42

Re: bash script local + remote server

Postby xepan » 2018-12-14 15:54

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
$ 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
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.
Posts: 89
Joined: 2018-11-28 06:38

Re: bash script local + remote server

Postby sabrina » 2018-12-15 09:11

Thanks :)
Posts: 2
Joined: 2018-12-14 12:42

Return to Programming

Who is online

Users browsing this forum: No registered users and 4 guests