ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
This is much more that just a SED script. If I understand you correctly, you will need to parse the ls -l listing, store the name of the file owner, and then write that to the file.
Can you give an example of where the info should be stored in the file---or should it just get appended?
Hint: First, run the individual commands on one file--to be sure that they do what you want. Then write the script.
Also, this does not look right:
for .htaccess in /home/*
This will find every file in /home and assign it to the variable ".htaccess". Is ".htaccess" an extension? If so, you need something like:
for file in /home/*.htaccess
oh ok thx, no .htaccess is just a file that restricts access for apache users. SO i mean every .htaccess file in every folder in home?? so not sure what to change it too
#!/bin/bash
for $.htaccess in /home/*;
do
$owner=`ls -l home$i|cut -d " " -f3`
sed -i "s@Require valid-user @Require user $owner@g" $.htaccess
done
"name" is a variable to which you are assigning the result of <something>. Suppose I do "ls" to list the contents of a directory.
for name in ls
As I go thru this loop, the variable "name" is given the value of each entry in the "ls" listing.
So---I think you need:
for name in /home/*/.htaccess
Then use $name in the later statements, as required.
What texts are you using for scripting? I recommend starting with the Bash Guide for Beginners by Machtelt Garrels. It's free at http://tldp.org
yeah im using bash script at the moment. Thx for the info
I got some errors?
./sed.sh: line 1: me: command not found
./sed.sh: line 2: =: command not found
./sed.sh: line 3: syntax error near unexpected token `do'
./sed.sh: line 3: `do'
#!/bin/bash
for name in /home/*/.htaccess
$owner=`ls -l /home$i|cut -d " " -f5`
do
sed -i "s@Require valid-user @Require user $owner@g" $name
done
Last edited by zerocool22; 06-05-2008 at 02:22 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.