Posted on 08-24-2015 06:17 AM
I have written a script to gather a bunch of fairly generic information from System Profiler and various log files, write it to a text file, and then zip up the text file in preparation for uploading to a drop box (write only) folder on an OS X file server.
I need to figure out how to programatically authenticate to the file server and copy the zip file over. I can't seem to get scp to work, as it would require a public/private key pair, and wont simply let me pass username and password into the command. This command needs to be totally hands-off for the user, as we are running this in the background. There is nothing sensitive or of security concern in the zipped up text, so I don't mind it being passed unencrypted to the file server. The user to be used for the copy would be write-only.
Ideas?
Solved! Go to Solution.
Posted on 08-24-2015 06:43 AM
You should have a look at the script in this JamfNation post.
You could easily modify the script to fit your needs but the overall function and syntax will do exactly what you're looking for.
Posted on 08-24-2015 06:43 AM
You should have a look at the script in this JamfNation post.
You could easily modify the script to fit your needs but the overall function and syntax will do exactly what you're looking for.
Posted on 08-24-2015 08:42 AM
Excellent. I have this mostly working but am getting an error from rsync. The files DO transfer, I'd like to do away with this error though:
Copying Data for Hostname: BOSDGREEN47366-2015-08-24
BOSDGREEN47366-2015-08-24.zip
7935233 100% 39.46MB/s 0:00:00 (xfer#1, to-check=0/1)
rsync: chgrp "/Volumes/Files/.BOSDGREEN47366-2015-08-24.zip.YI1yxi" failed: Operation not permitted (1)
sent 7938028 bytes received 42 bytes 5292046.67 bytes/sec
total size is 7935233 speedup is 1.00
rsync error: some files could not be transferred (code 23) at /SourceCache/rsync/rsync-45/rsync/main.c(992) [sender=2.6.9]
bash-3.2#
Posted on 08-24-2015 08:46 AM
Are you manually running the script or thru running it thru Casper? I'm betting manually because I've seen that before when running manually. The issue went away when it ran thru the JSS since scripts are run as root.
Shaun
Posted on 08-24-2015 08:48 AM
Aha! Yes, I am running it locally for now. I'll upload it to the JSS and see what happens. Thanks for the help! Much appreciated!
Posted on 08-24-2015 08:53 AM
Happy to help... Let me know how the testing goes!!
Just for awareness the error you're seeing is an rsync perms error and depending on the switches you are using in the rsync command will display or suppress the error. I never looked into it more since it worked as far as I could tell from the JSS.
Posted on 08-24-2015 09:22 AM
Hmmm I am seeing the same error when run via the JSS:
Copying Data for Hostname: BOSDGREEN47366-C02M7AB3FD57-2015-08-24
BOSDGREEN47366-C02M7AB3FD57-2015-08-24.zip
32768 0% 0.00kB/s 0:00:00
7968490 100% 42.28MB/s 0:00:00 (xfer#1, to-check=0/1)
rsync: chgrp "/Volumes/Files/.BOSDGREEN47366-C02M7AB3FD57-2015-08-24.zip.r3I3rD" failed: Operation not permitted (1)
sent 7971309 bytes received 42 bytes 15942702.00 bytes/sec
total size is 7968490 speedup is 1.00
rsync error: some files could not be transferred (code 23) at /SourceCache/rsync/rsync-45/rsync/main.c(992) [sender=2.6.9]
Finished Copying Data for Hostname: BOSDGREEN47366-C02M7AB3FD57-2015-08-24
Posted on 08-24-2015 09:32 AM
I did find that if I used
rsync --ignore-errors --force --progress /"$DESTDIR"/"$CNAME"-"$serial"-"$DATE".zip /Volumes/Files
that worked with a successful policy log in the JSS.
If I used rsync -vzog --ignore-errors --force --progress /"$DESTDIR"/"$CNAME"-"$DATE".zip /Volumes/Files
that results in a failed policy log, though it does complete.
Posted on 08-24-2015 10:24 AM
Ahhh those details help a bit more to see what's going on... using the RSYNC switch -vzog means:
V - Verbose
Z - Compress
O - Preserve Owner
G - Preserve Group
Without using those switches the file would get stripped of those settings and sounds like that is working without issue and inheriting whatever permissions are on the target drive. If retaining those parameters isn't important than the top command would work just fine.
If those are important you will need to find out why keeping those parameters is throwing up log errors.
Posted on 08-24-2015 10:36 AM
The permissions really don't matter to me as I am going to chmod -r 777 the destination directory before supply the collected data to anyone.
Posted on 08-24-2015 10:42 AM
So it sounds like using the top command works and should get you what you need then unless I'm missing something.
Posted on 08-24-2015 10:47 AM
Yes it sure does! I am testing the complete script out on my local support guys as we speak! Thanks again for the help!