Remote sudo with redirect


/ Published in: Bash
Save to your folder(s)

Ever wanted to execute remote commands with sudo while redirecting output to a file that doesn't belong to the user you login with? Combine single quotes with double quotes!


Copy this code and paste it in your HTML
  1. for server in one two three; do
  2. ssh $server sudo bash -c "'cat >> /some/file << EOF
  3. Some Content
  4. EOF'"
  5. done

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.