LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-27-2008, 09:03 AM   #16
zerocool22
Member
 
Registered: Feb 2008
Posts: 95

Original Poster
Rep: Reputation: 15

Quote:
#!/bin/bash

for i in $( ls /backup ) ; do
if [ -d /backup/$i ]; then
chown --reference=/home/$i /backup/$i
else
echo ls /backup/$i
fi
for j in $( ls /backup/$i ) ; do
if [ -d /backup/$i/$j ]; then
chown -R --reference=/home/$i/$j /backup/$i/$j

else
echo ls /backup/$i/$j
fi
done
done
here ya go
 
Old 05-27-2008, 09:32 AM   #17
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by zerocool22 View Post
here ya go
I don't understand what you're trying to achieve.

I presume you have a series of user directories under /home and you want the permissions of the directories in /backup to match those. If that is the case, then the following might be more suitable:
Code:
for dir in /home/*; do 
   chown -R --reference=$dir /backup/$(basename $dir)
done
 
Old 05-27-2008, 09:35 AM   #18
zerocool22
Member
 
Registered: Feb 2008
Posts: 95

Original Poster
Rep: Reputation: 15
mine works aswell? why should i go your way?

I have /home/ folders with user/group properties on them, now i need to match them to my /backup/ folders which contain the same folders, but different content.
 
Old 05-27-2008, 10:51 AM   #19
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by zerocool22 View Post
mine works aswell? why should i go your way?
If yours works, that's fine - use that.
 
Old 05-28-2008, 03:23 AM   #20
zerocool22
Member
 
Registered: Feb 2008
Posts: 95

Original Poster
Rep: Reputation: 15
one last question about this, cause im still having some troubles, so the home folder properties are getting copied to backup nicely. But sometimes /home/ has a folder that doesnt excist in /backup/ like for example /home/tompie but there is no /backup/tompie so the properties cant be copied to backup. So i want to list all folders that do excist on home but not on backup.

I thought i was doing that by saying if [ -d /backup/$i ]; then
else
echo ls /backup/$i

But he doesnt list any to the screen??
 
Old 05-28-2008, 03:56 AM   #21
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by zerocool22 View Post
one last question about this, cause im still having some troubles, so the home folder properties are getting copied to backup nicely. But sometimes /home/ has a folder that doesnt excist in /backup/ like for example /home/tompie but there is no /backup/tompie so the properties cant be copied to backup. So i want to list all folders that do excist on home but not on backup.

I thought i was doing that by saying if [ -d /backup/$i ]; then
else
echo ls /backup/$i

But he doesnt list any to the screen??
All that snippet of code says is, if /backup/$i is a directory, then chown it, otherwise, list its contents. It doesn't check to see if it's present in /home too. To do that, you might do something like:
Code:
for dir in $(ls /home/); do
   if [[ -d /home/$dir && -d /backup/$dir ]]; then
      do whatever you want
   else
      echo some error message
   fi
done
That will check to see if a directory exists in both /home and /backup, and if so, then you can run whatever command you want on both the files. If it only exists in one (either /home or /backup), then you can print out some error message.

Hope this helps.
 
Old 06-01-2008, 02:16 AM   #22
maooah
Member
 
Registered: Dec 2007
Posts: 44

Rep: Reputation: 15
hi experts

why do we start scripts the first line beginning with below statement:

#!/bin/bash

waiting for reply

Regards
 
Old 06-01-2008, 07:53 AM   #23
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by maooah View Post
hi experts

why do we start scripts the first line beginning with below statement:

#!/bin/bash

waiting for reply

Regards
http://en.wikipedia.org/wiki/Shebang_(Unix)

You would have probably been better off starting a new thread for this question as it really isn't that related to the rest of this thread.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Makefile:condition to check whether a file exists ? Ashok_mittal Linux - Newbie 4 12-06-2011 07:52 PM
IMAP folder exists but invisible in Outlook&Webclient demsab Linux - Software 4 03-07-2008 01:13 AM
how to make ln check whether target exists bkeeper Linux - Software 2 12-23-2005 03:51 AM
ksh check if file exists (using wildcard) problem r18044 Linux - Newbie 5 02-22-2005 07:52 AM
c++ check if file exists Genjix Programming 3 03-15-2004 12:08 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration