- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script Help Needed
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
02-24-2005 12:23 PM
02-24-2005 12:23 PM
I am wanting to write a script to do something like the following. Sorry if this seems easy to some of you, but scripting is not my strength:
# ls a directory > file
# Ask the user for input
# If the input is not in the file, echo an error
# If the input is a blank, space, or ENTER, echo an error
Thanks for your help.
Bobby
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2005 12:40 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2005 12:51 PM
02-24-2005 12:51 PM
Re: Script Help Needed
a user supplied string in it, you are basically trying to
findout if the a file with user supplied name exists in
that directory of not. To do this, a simpler way
would be:
DIR="/your_dir"
echo "Enter file name"
read file
if [ $FILE = "" ]
then
echo "Illegal file name"
exit 1
fi
if [ -a $DIR/file ]
then
echo "File exists"
else
echo "File not found"
fi
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2005 01:50 PM
02-24-2005 01:50 PM
Re: Script Help Needed
How can I modify this so that I can grep out any file in the ls listing that starts with a "d" ? Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2005 07:58 PM
02-24-2005 07:58 PM
Re: Script Help Needed
ls a*
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2005 08:12 PM
02-24-2005 08:12 PM
Re: Script Help Needed
#!/bin/ksh
# check files
# User input
echo "Enter your input"
read input
# check
if [[ -z $input ]]
then
echo "ERROR: User input $input is blank"
exit 1
fi
rm -f /tmp/testlog
# Grep in the a* starting files
for file in `find . -type f -name "a*"`
do
grep $input $file >/tmp/testlog
if [[ $? -eq 0 ]]
then
cat /tmp/testlog
else
echo "ERROR: Used input $input is not file $file"
fi
done
rm -f /tmp/testlog
exit 0
### end ###
Let me know if you have issues.
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2005 08:59 PM
02-24-2005 08:59 PM
Re: Script Help Needed
I will do this way:
Say my script name is prg and written in korn shell.
# chmod +x prg1.sh
# cat prg
#!/usr/bin/ksh
list=`ls $1`
echo " Enter File Name: \n"
read j
for i in $list
do
if [ "$i" = "$j" ]
then
echo "\n Your file exists in the directory \n"
exit
fi
done
echo "\n Your file doesn't exists in the directory \n"
#
#
# ls /directory
file1 file2 file3
#
# ./prg directory
Enter File Name:
file6
Your file doesn't exists in the directory
# ./prg directory
Enter File Name:
file3
Your file exists in the directory
#
Hope that helps.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2005 09:38 PM
02-24-2005 09:38 PM
Re: Script Help Needed
Modified scritp to list files starting with "a".
#!/usr/bin/ksh
list=`ls $1 | grep ^a`
echo " Enter File Name: \n"
read j
for i in $list
do
if [ "$i" = "$j" ]
then
echo "\n Your file exists in the directory \n"
exit
fi
done
echo "\n Your file doesn't exists in the directory \n"
#
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2005 02:19 PM
03-02-2005 02:19 PM