- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Directory check
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
Discussions
Discussions
Forums
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
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
тАО10-06-2006 03:18 AM
тАО10-06-2006 03:18 AM
Basically what I would like to do is the user inputs a name, then a script checks whether the directory exist. If it does not exist then create the directory and subdirectories. Also chmod -R 777. The script should be able to check this from any directory that it is run from.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-06-2006 03:34 AM
тАО10-06-2006 03:34 AM
Re: Directory check
#!/usr/bin/sh
echo "Enter Dir Name: "
read DIRNAME
if [[ -d ${DIRNAME} ]] ; then
echo "Dir Exists"
else
echo "Dir does not exist"
mkdir ${DIRNAME}
chmod 770 ${DIRNAME}
fi
You notice I didnot chmod 777. 777 are VERY VERY VERY BAD permissions. That means that ANYBODY on the server can royall screw up anything in that directory.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-06-2006 03:37 AM
тАО10-06-2006 03:37 AM
Re: Directory check
Secondly, user input must contain full path otherwise you won't know where to start with
#!/usr/bin/ksh
ls -l $1
if [ $? -eq 0 ] ; then
echo $1 " exists"
else
mkdir -p $1
chmod -R 777 $1
echo $1 " has been created"
fi
exit
call it dirchk.sh
user need to run it like "dirchk.sh /aaa/bbb/ccc"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-06-2006 03:40 AM
тАО10-06-2006 03:40 AM
Re: Directory check
#!/usr/bin/sh
typeset DNAME=""
typeset STAT=255
echo "Enter directory name: \c"
read DNAME
if [ -e "${DNAME}" ]
then
echo "${DNAME} already exists.] >&2
else
mkdir "${DNAME}"
STAT=${?}
if [ ${STAT} -ne 0 ]
then
echo "Cannot mkdir ${DNAME}; status ${STAT}." >72
fi
exit ${STAT}
I have no idea what the subdirectories should be. It should be obvious where your chmod goes but setting mode to 777 should be done only in extremely rare cases; it is a huge security hole.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-07-2006 08:05 AM
тАО10-07-2006 08:05 AM
Re: Directory check
if you use
umask 0
mkdir -p -m 777 dirname
you will get all you need (whether it makes sense to have world writable directories or not).
In this form you will
- not get an error message for existing directories
- an error message if the creation failes
- the exit status will be accordingly
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-10-2006 04:05 AM
тАО10-10-2006 04:05 AM
Re: Directory check
I have tried using the tr command to no success as follows.
LUsr=`echo $DIRNAME | tr'[:upper:]''[:lower:]'`
What am I doing wrong here?
I also tried the following:
LUsr=`nawk '{print tolower($DIRNAME)}'`
- Tags:
- tr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-10-2006 04:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-10-2006 05:06 AM
тАО10-10-2006 05:06 AM
Re: Directory check
If you are collecting your data interactively, use 'typeset -l' to lowercase your input:
# typeset -l NAME
# read NAME
# echo ${NAME}
Regards!
...JRF...
- Tags:
- typeset
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-12-2006 01:20 AM
тАО10-12-2006 01:20 AM