The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to save files in /tmp???? wrapster SUN Solaris 3 02-24-2008 10:31 PM
Korn Shell Script to change the permissions uhelp Linux 1 12-01-2006 09:19 PM
Shell script permissions tmikahan Shell Programming and Scripting 1 06-15-2006 08:48 AM
can I save list of files in memory and not in text file? umen Shell Programming and Scripting 1 06-05-2006 05:27 AM
how to save files? hiei UNIX for Dummies Questions & Answers 2 04-01-2004 01:08 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-09-2007
joangopan joangopan is offline
Registered User
  
 

Join Date: Sep 2007
Location: Mexico DF
Posts: 2
Shell Script to save/restore files and dir permissions

Hello all:

I need found script to save and restore file permissions and owner:group... this is for backup my server...

I have one problem in my server and file permissions and owner:group, mess up..

For this reason i need found one way to secure this aspect of the server...

Thanks!
  #2 (permalink)  
Old 01-13-2009
apaxmai apaxmai is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 1
Wrote this little guy up for you



saveState.pl

Code:
my $tree = $ARGV[0];

foreach $file (`/usr/bin/find ${tree}`)
{
  chomp($file);
  (undef, $inode, $mode, undef, $uid, $gid, $undef, $size, undef, undef, undef, undef, undef) = stat($file);
  $permissions = $mode & 07777;
  printf "%i:%i:%04o:%i:%i:%s\n", $inode, $size, $permissions, $uid, $gid, $file;
}

applyState.pl

Code:
#Does not save ACL...

my $stateFile = $ARGV[0];

open(STATE_IN, "<$stateFile");

foreach $line (<STATE_IN>)
{
  chomp($line);
  my ($inode, $size, $permissions, $uid, $gid, $file) = split(':', $line, 6);
  if( -f $file )
  {
    #add inode / size check here if desired
    chmod(oct($permissions), $file);
    chown($uid, $gid, $file);
  }
}

close(STATE_IN);

########################## Example #################

Code:
9:45am root@hyperion  /research/src/state_saver #>perl saveState.pl /research/src/state_saver/ > test

9:45am root@hyperion  /research/src/state_saver #>cat test
1846211:512:0755:0:0:/research/src/state_saver/
1846214:0:0644:0:0:/research/src/state_saver/test
1846213:365:0644:0:0:/research/src/state_saver/applyState.pl
1846212:332:0644:0:0:/research/src/state_saver/saveState.pl

9:45am root@hyperion  /research/src/state_saver #>l
total 10
   1846211 drwxr-xr-x   2 root     root         512 Jan 13 09:45 .
   1846210 drwxr-xr-x   3 root     root         512 Jan 13 09:30 ..
   1846213 -rw-r--r--   1 root     root         365 Jan 13 09:44 applyState.pl
   1846212 -rw-r--r--   1 root     root         332 Jan 13 09:44 saveState.pl
   1846214 -rw-r--r--   1 root     root         219 Jan 13 09:45 test

9:45am root@hyperion  /research/src/state_saver #>chmod 777 saveState.pl 

9:45am root@hyperion  /research/src/state_saver #>l
total 10
   1846211 drwxr-xr-x   2 root     root         512 Jan 13 09:45 .
   1846210 drwxr-xr-x   3 root     root         512 Jan 13 09:30 ..
   1846213 -rw-r--r--   1 root     root         365 Jan 13 09:44 applyState.pl
   1846212 -rwxrwxrwx   1 root     root         332 Jan 13 09:44 saveState.pl
   1846214 -rw-r--r--   1 root     root         219 Jan 13 09:45 test

9:45am root@hyperion  /research/src/state_saver #>perl applyState.pl test 

9:46am root@hyperion  /research/src/state_saver #>l
total 10
   1846211 drwxr-xr-x   2 root     root         512 Jan 13 09:45 .
   1846210 drwxr-xr-x   3 root     root         512 Jan 13 09:30 ..
   1846213 -rw-r--r--   1 root     root         363 Jan 13 09:46 applyState.pl
   1846212 -rw-r--r--   1 root     root         332 Jan 13 09:44 saveState.pl
   1846214 -rw-r--r--   1 root     root         219 Jan 13 09:45 test

9:46am root@hyperion  /research/src/state_saver #>

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0