linux - sudo in bash, permission denied -
this question has answer here:
i want block usb mass storage in of systems in lan. have written bash script modify file. running script default admin in ubuntu. script not able modify file. getting following error "bash: /etc/modprobe.d/blacklist.conf: permission denied"
below bash script
#/bin/bash password='mypassword' #admin password of remote system val='blacklist usb-storage' #text want add in file sysname in $(cat systemdetails) #systemdetails file stores ssh $sysname 'echo '$password' | sudo -s echo '$val ' >> /etc/modprobe.d/blacklist.conf' echo done #script ends
note: have configured system such no ssh password required.
any pointers in regard helpful.
try this:
ssh $sysname "echo $password | sudo -s sh -c 'echo $val >> /etc/modprobe.d/blacklist.conf'"
Comments
Post a Comment