- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script for file permission & owner
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2008 05:10 AM
08-05-2008 05:10 AM
i would required .sh script to achive below mention task.
1) chown "defind by me" + chmod "define by me" to all the files with in the folder.
2)it will log all the above activity to a file so that i can check the log and ensure.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2008 05:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2008 05:18 AM
08-05-2008 05:18 AM
Re: Script for file permission & owner
sounds like homework to me.
The task defined in number 1 above doesn't seem to make sense.
export LOGFILE=/tmp/mylog
chown myid:mygroup * >> $LOGFILE
chmod 777 * >> $LOGFILE
There you go, two command and a log of the activity/output.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2008 06:01 AM
08-05-2008 06:01 AM
Re: Script for file permission & owner
#!/usr/bin/ksh
# $1 for owner, $2 for permission:
LOGFILE=/tmp/mylog
chown $1 * >> $LOGFILE 2>&1
chmod $2 * >> $LOGFILE 2>&1
Note this only logs errors. If you want to log the whole command, you can add echo before each of the above commands:
echo "chown $1 *" >> $LOGFILE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2008 06:48 AM
08-05-2008 06:48 AM
Re: Script for file permission & owner
## script to update ownership and permissions on all files in a given directory
!#/bin/sh
export DIR=/directory_path
export LOGFILE=/log_fiel_path
chown -R username:groupname DIR
if[$?==0]
{
echo "`date` >> LOGFILE
echo "Current operation is successful" >> LOGFILE
else
echo "`date` >> LOGFILE
echo "Please check $LOGFILE for errors" >> LOGFILE
fi
chmod -R permission(e.g. 755) DIR
if[$?==0]
{
echo "`date` >> LOGFILE
echo "Current operation is successful" >> LOGFILE
else
echo "`date` >> LOGFILE
echo "Please check $LOGFILE for errors" >> LOGFILE
fi
ls -lrt DIR >> LOGFILE
echo "Please check $LOGFILE for verification"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2008 08:43 PM
08-06-2008 08:43 PM
Re: Script for file permission & owner
I have tried the scipt give above but it gives following errors.
./newtest.sh[8]: if[0==0]: not found.
./newtest.sh[9]: Syntax error at line 16 : `fi' is not expected.
Please help me out to rectify the same.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2008 09:53 PM
08-06-2008 09:53 PM
Re: Script for file permission & owner
./newtest.sh[8]: if[0==0]: not found.
The proper syntax is:
if [ $? -eq 0 ]; then
(And remove that "{" on the next line.)
You have a very low point assignment rating:
assigned points to 18 of 164
http://forums.itrc.hp.com/service/forums/pageList.do?userId=CA1422193&listType=unassigned&forumId=1
If you don't fix this, you will be struck off and not get any answers. :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2008 10:40 PM
08-06-2008 10:40 PM
Re: Script for file permission & owner
Still gives the following error any help
# ./newtest.sh
./newtest.sh[8]: if[0: not found.
./newtest.sh[15]: Syntax error at line 16 : `fi' is not expected.
________________________________________
## script to update ownership and permissions on all files in a given directory
#!/bin/sh
export DIR=/tmp/abc
export LOGFILE=/tmp/abc/log_file.log
chown -R hpyjipat:sys DIR
if[$? -eq 0];
echo "`date` >> LOGFILE
echo "Current operation is successful" >> LOGFILE
else
echo "`date` >> LOGFILE
echo "Please check $LOGFILE for errors" >> LOGFILE
fi
chmod -R 700 DIR
if[$? -eq 0];
echo "`date` >> LOGFILE
echo "Current operation is successful" >> LOGFILE
else
echo "`date` >> LOGFILE
echo "Please check $LOGFILE for errors" >> LOGFILE
fi
ls -lrt DIR >> LOGFILE
echo "Please check $LOGFILE for verification"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2008 09:51 AM
08-07-2008 09:51 AM
Re: Script for file permission & owner
>if[$? -eq 0];
This isn't exactly what I showed. Every stinkin' space is important. You need to cut & paste:
if [ $? -eq 0 ]; then
>Points are assigned.
You still have to assign points to 130+ replies, back to Jan 2007:
http://forums.itrc.hp.com/service/forums/pageList.do?userId=CA1422193&listType=unassigned&forumId=1