- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: awk help PLEASE
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
тАО02-24-2005 09:45 AM
тАО02-24-2005 09:45 AM
Anyhow, all I'm trying to do is determine if a file already exists. I read that the "ls /Backups" command (or any getline cmd) will only execute ONE time (I was thinking that it would execute once for each input record, WRONG).
My real question is... How do i determine if a file already exist without getting an error or system error.
BEGIN { }
{
x=0
while ("ls /Backups" | getline fl)
{
print fl " == " $1 " and x is " x
if ( test fl == $1 ) x=1
}
if (x == 0)
{
print x
system("mkdir /Backups/" $1 )
}
}
THANK YOU
David
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2005 09:57 AM
тАО02-24-2005 09:57 AM
Re: awk help PLEASE
{
x = 0
while ((x < 1) && "ls /Backups 2>/dev/null" | getline fl)
{
++x
}
if (x < 1)
{
print "File not found"
}
else
{
print "File found"
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2005 10:17 AM
тАО02-24-2005 10:17 AM
Re: awk help PLEASE
while ("ls /Backups" | getline fl)
ONLY happens one time for each input file. The problem is when there is more than one line in an input file.
The actual error that I'm trying to avoid is on system mkdir command. Although it works without displaying an error, I'm not too thrilled with
system("mkdir /Backups/" $1 " 2>/dev/null")
- Tags:
- mkdir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2005 10:33 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2005 10:36 AM
тАО02-24-2005 10:36 AM
Re: awk help PLEASE
while (( "ls /tmp" | getline def ) > 0 ) {
print def;
}
close("ls /tmp");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2005 03:28 PM
тАО02-24-2005 03:28 PM
Re: awk help PLEASE
perl -e '$dir = "/Backups/$name"; mkdir ($dir,0777) unless (-d $dir)'
fwiw,
Hein.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2005 06:21 PM
тАО02-24-2005 06:21 PM
Re: awk help PLEASE
[[ ! -d muthu ]] && mkdir muthu
To do with AWK using your style then,
--- test. awk ---
BEGIN { }
{
x=0
while ("[[ -d muthu ]] && ls muthu"| getline fl)
{
print fl " == " $1 " and x is " x
if ( test fl == $1 ) x=1
}
}
END {
if (x == 0)
{
print x
system("mkdir muthu")
}
}
# awk -f test.awk
0
#
That is all.
Problem you had,
1. Try to do check and create new directory in the END part only.
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-24-2005 08:42 PM
тАО02-24-2005 08:42 PM
Re: awk help PLEASE
if [[ -d /Backups ]]
then
echo "Directory /Backups exists"
fi
if [[ -a /Backups/filename ]]
then
echo "filename exists"
fi