Check out the 'stat' command and 'stat -t'.
Unfortunately it gives full modes in HEX! Some shell hackery: set -- $(ls -l foo) OCTMODE=$(echo "ibase=2;obase=8;$(echo $1 | tr -- '-drlwcxb' '0 1 1 1 ')" | bc) Season to taste. Tweak for hex to octal conversion. ccb -- Charles C. Bennett, Jr. VA LiNUX Systems Systems Engineer, Northeast US 25 Burlington Mall Rd., Suite 300 +1 617 543-6513 Burlington, MA 01803-4145 ccb@valinux.com www.valinux.com
On Thu, 19 Jul 2001 ccb@acm.org wrote:
Check out the 'stat' command and 'stat -t'.
Unfortunately it gives full modes in HEX!
Oh, that's what that was. Without the -t looked promising, but with the -t I couldn't find the value I expected. Thank you anyway Charles.
Some shell hackery: set -- $(ls -l foo) OCTMODE=$(echo "ibase=2;obase=8;$(echo $1 | tr -- '-drlwcxb' '0 1 1 1 ')" | bc)
Indeed, many thanks. My script was going to be something along the lines of awk/if-then-else-fi/echo. :-) Can this be tweaked for directories also? You lost me after tr. -- Gary
On Thu, Jul 19, 2001 at 12:50:28AM -0400, Gary J. Hanley wrote: ghanley> On Thu, 19 Jul 2001 ccb@acm.org wrote: ghanley> > > Check out the 'stat' command and 'stat -t'. ghanley> > ghanley> > Unfortunately it gives full modes in HEX! ghanley> ghanley> Oh, that's what that was. Without the -t looked promising, but with the -t ghanley> I couldn't find the value I expected. Thank you anyway Charles. I figured you'd use the version without the -t like this: stat file | grep "Access: (" | cut -d\( -f2 | cut -d/ -f1 It works with directories too.
On Thu, 19 Jul 2001, Charles R . Anderson wrote:
I figured you'd use the version without the -t like this: stat file | grep "Access: (" | cut -d\( -f2 | cut -d/ -f1
Definately possible. I have to make sure the permissions on a large number of files and directories are in sync with a remote system so I want to make sure I can generate this list in the most efficient way.
It works with directories too.
Big plus. :-) Thanks Charles. -- Gary
On Thu, Jul 19, 2001 at 09:53:47AM -0400, Gary J. Hanley wrote: ghanley> Definately possible. I have to make sure the permissions on a large number ghanley> of files and directories are in sync with a remote system so I want to make ghanley> sure I can generate this list in the most efficient way. Sounds like a job for rsync. It can synchronize files, links, devices, directories, owners, groups, and permissions. It will only transfer the "differences" over the network, making it extremely fast. These options should do what you want (but I haven't tested this): -p, --perms This option causes rsync to update the remote permissions to be the same as the local permissions. --existing This tells rsync not to create any new files - only update files that already exist on the destination. I'm not sure if rsync can synchronize JUST permissions, and not file contents as well. It might be worth looking into, though.
The host is at secure site. Can rsync use a secure socket like ssh? I guessed that it couldn't but I'll admit I didn't look into it. -- Gary On Thu, 19 Jul 2001, Charles R . Anderson wrote:
On Thu, Jul 19, 2001 at 09:53:47AM -0400, Gary J. Hanley wrote: ghanley> Definately possible. I have to make sure the permissions on a large number ghanley> of files and directories are in sync with a remote system so I want to make ghanley> sure I can generate this list in the most efficient way.
Sounds like a job for rsync. It can synchronize files, links, devices, directories, owners, groups, and permissions. It will only transfer the "differences" over the network, making it extremely fast. These options should do what you want (but I haven't tested this):
-p, --perms This option causes rsync to update the remote permissions to be the same as the local permissions.
--existing This tells rsync not to create any new files - only update files that already exist on the destination.
I'm not sure if rsync can synchronize JUST permissions, and not file contents as well. It might be worth looking into, though. _______________________________________________ Wlug mailing list Wlug@mail.wlug.org http://mail.wlug.org/mailman/listinfo/wlug
On Thu, Jul 19, 2001 at 10:25:24AM -0400, Gary J. Hanley wrote: ghanley> The host is at secure site. Can rsync use a secure socket like ssh? I ghanley> guessed that it couldn't but I'll admit I didn't look into it. Yes, it can use rsh or ssh or its own rsync server daemon.
Gary J. Hanley said:
The host is at secure site. Can rsync use a secure socket like ssh? I guessed that it couldn't but I'll admit I didn't look into it.
-- Gary
rsync rocks. Until recently (when I got a cable modem) I'd rsync my debian archive to a box on a slightly better connection with this: /usr/bin/rsync -avPe /usr/bin/ssh --exclude "*tmp*" --exclude "Makefile" --exclude \ "*.m4" --exclude "stdlib.mc" --delete /home/orion/public_html/zork/ zork.net:~/public_html/ I also know someone who uses rsync to do a selective daily backup to another partition: rsync -axS --partial --stats --delete --delete-excluded --exclude-from=/etc/backup.exclude /etc /usr/local /var/spool/mail /var/lib/mailman /var/cache/backup/ and offsite: rsync -azxS -e ssh --stats --partial --delete /var/cache/backup/ two-bit.northpark.edu:/usr/local/var/backup/ -- Aaron Haviland orion [at] tribble [dot] dyndns [dot] org orion [at] parsed [dot] net So I can get 1 bpm by flashing a mirror?
Can this be tweaked for directories also? You lost me after tr.
Check it out: tr -- '-drlwcxb' '0 1 1 1 ' Says (somewhat obfuscatedly): --: ignore the - in the next string '-drlwcxb': characters to match on input '0 1 1 1 ': characters to replace with The mapping is positional: - becomes 0 d becomes space r becomes 1 l becomes space w becomes 1 c becomes space x becomes 1 b becomes space "season to taste" implies that you'd hack in cases for 'p' '=' and the few remaining other cases. You'll also need to map 's' and 't' to 1 to cover setuid/setgid and sticky. If you need to know about the setuid/setgid and sticky bits and the file type stuff you can let tr pass them and them scan: FMODE=$(echo $STR|tr 'rwx' '111') # check file types case "$FMODE" in b*) # block file stuff FT=0110 ;; c*) # char file stuff FT=0010 ;; d*) # directory stuff FT=0100 ;; l*) # symlink stuff FT=1010 ;; p*) # named pipe (fifo) stuff FT=0001 ;; =*) # socket file stuff FT=1010 ;; -*) # regular file stuff FT=1000 ;; esac # check higher bits case "$FMODE" in ???s??????) # setuid stuff XM=100 ;; ??????s???) # setgid stuff XM=010 ;; ?????????t) # sticky stuff XM=001 ;; esac # normalize file types to ' ' and s, t bits to 1 BINMODE=$(echo $FMODE | tr -- '-bcdlp=st' ' 11') # translate full mode to octal OCTMODE=$(echo "ibase=2; obase=8; $FT$XM$FMODE" | bc) At some point you wake up to stuff like: perl -e '@x = stat("foo"); printf "%o\n", $x[2]' ccb -- Charles C. Bennett, Jr. VA LiNUX Systems Systems Engineer, Northeast US 25 Burlington Mall Rd., Suite 300 +1 617 543-6513 Burlington, MA 01803-4145 ccb@valinux.com www.valinux.com
participants (4)
-
Aaron Haviland
-
ccb@acm.org
-
Charles R . Anderson
-
Gary J. Hanley