I’m having an issue with my script. The variables X and Y are assigned the last octet of an IP address and work fine. Z is supposed to take X and Y and put the values into a new txt file.
X=$(ssh -i key.txt "$USER"@A.B.C.D "awk -F' ' '{print \$2}' /etc/openvpn/ccd/lastip.txt | awk -F'.' '{print \$4+4}'")
Y=$(ssh -i key.txt "$USER"@A.B.C.D "awk -F' ' '{print \$3}' /etc/openvpn/ccd/lastip.txt | awk -F'.' '{print \$4+4}'")
Z=$(ssh -i key.txt "$USER"@A.B.C.D "touch $NAME.txt | chmod 700 $NAME.txt mv $NAME.txt /etc/openvpn/ccd | echo -n "$X $Y" > /etc/openvpn/ccd/$NAME.txt")
I keep getting messages say permission denied:
mv: bash: /etc/openvpn/ccd/almost.txt: Permission denied
cannot move `almost.txt' to `/etc/openvpn/ccd/almost.txt': Permission denied
The directory exists and the permission for it are fine. How would I go about being able to move $NAME.txt into my desired directory?
EDIT: Even without Z=$() and using the command line, I still get permission denied errors
This bit needs some work:
At minimum, you need to replace the pipes with semicolons, and one of the spaces too:
It does not look plausible that you want to execute
$NAME.txt; you should not use 700 but 600 permissions.Since you didn’t have a semicolon before the
mv, thechmodprogram tried to change permissions on filesmv,$NAME.txta second time, and/etc/openvpn/ccd.Unless you are running as
root, you should not be able to write in/etc/openvpn/ccd. However, you have not shown us the permissions on the current directory, though sincetouchappears to have worked, you can presumably write in that. Nor, at the time I wrote this, were the permissions on/etc/openvpn/ccdgiven — but see below.And, as John Kugleman notes in a comment, in the larger context where the command string I dissected is inside a set of double quotes, the double quotes around
"$X $Y"should be escaped with backslashes:Source of ‘no permission’ error
Given that the permissions on
/etc/openvpn/ccdare:we can infer that you are not running as
rootand are not permitted to write in the directory. You may need to get permission to usesudoon the target machine.