-
Notifications
You must be signed in to change notification settings - Fork 0
/
72b-ssync
46 lines (33 loc) · 1023 Bytes
/
72b-ssync
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# ssync--If anything has changed, creates a tarball and syncs a remote
# directory via sftp using sftpsync.
sftpacct="[email protected]"
tarballname="AllFiles.tgz"
localsource="$HOME/Desktop/Wicked Cool Scripts/scripts"
remotedir="/wicked/scripts"
timestamp=".timestamp"
count=0
# First off, let's see if the local dir exists and has files.
if [ ! -d "$localsource" ] ; then
echo "$0: Error: directory $localsource doesn't exist?" >&2
exit 1
fi
cd "$localsource"
# Now let's count files to ensure something's changed.
if [ ! -f $timestamp ] ; then
for filename in *
do
if [ -f "$filename" ] ; then
count=$(( $count + 1 ))
fi
done
else
count=$(find . -newer $timestamp -type f -print | wc -l)
fi
if [ $count -eq 0 ] ; then
echo "$(basename $0): No files found in $localsource to sync with remote."; exit 0
fi
echo "Making tarball archive file for upload"
tar -czf $tarballname ./*
# Done! Now let's switch to the sftpsync script.
exec sftpsync $sftpacct $remotedir