HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- functions
Operating System - HP-UX
1827855
Members
2705
Online
109969
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
04-12-2005 03:09 AM
04-12-2005 03:09 AM
functions
hi all
i want to ask about
how can i use functions like (stat,lstat,..)
in my script?
i writes scripts using sh and korn?
when i type any of this commands in prompt
it return error
sh:lstat : not found
please explain
thankx
i want to ask about
how can i use functions like (stat,lstat,..)
in my script?
i writes scripts using sh and korn?
when i type any of this commands in prompt
it return error
sh:lstat : not found
please explain
thankx
- Tags:
- stat
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2005 03:19 AM
04-12-2005 03:19 AM
Re: functions
Strictly speaking stat() and lstat() are system calls and you cannot use them from the shell. Learn C/C++ then you can use them. Now you create a c program that invokes stat() and outputs to stdout and then you could use that command in a shell script.
A much better solution is to use Perl. If has both the stat() and lstat() functions built-in.
You could even do something like this:
#!/usr/bin/sh
STAT=$(perl -e stat("/tmp"))
echo "STAT = ${STAT}"
but you would really need to fprmat the stat output to be meaningful too you.
The best answer is to learn Perl and do your scripting in it.
A much better solution is to use Perl. If has both the stat() and lstat() functions built-in.
You could even do something like this:
#!/usr/bin/sh
STAT=$(perl -e stat("/tmp"))
echo "STAT = ${STAT}"
but you would really need to fprmat the stat output to be meaningful too you.
The best answer is to learn Perl and do your scripting in it.
If it ain't broke, I can fix that.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2005 07:30 AM
04-12-2005 07:30 AM
Re: functions
I really should give you a little better example in Perl:
perl -e '@x = stat("/tmp"); foreach $x (@x) {print $x," ";} print "\n";'
This is untested but it should at least give you the fields separated by a space. You should note that the times are epoch seconds so you still have some work to do. Mode would be more meaningful is printed in octal but I 'll leave all that to you.
perl -e '@x = stat("/tmp"); foreach $x (@x) {print $x," ";} print "\n";'
This is untested but it should at least give you the fields separated by a space. You should note that the times are epoch seconds so you still have some work to do. Mode would be more meaningful is printed in octal but I 'll leave all that to you.
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2005 02:19 PM
04-12-2005 02:19 PM
Re: functions
Here is how you can use the stat() in C
When you use this function it actually returns you a pointer to a structure "stat" which defines all the parameters of a file, below is a simple example which when compiled and run bu passing a file return the inode and the size of the file
#include
#include
#include
main (argc, argv)
int argc;
char *argv[];
{
struct stat buf;
stat(argv[1], &buf);
printf("The file size are: %ld\n", buf.st_size);
printf("The file inode are: %ld\n", buf.st_ino);
}
Cheers
Rajeev
When you use this function it actually returns you a pointer to a structure "stat" which defines all the parameters of a file, below is a simple example which when compiled and run bu passing a file return the inode and the size of the file
#include
#include
#include
main (argc, argv)
int argc;
char *argv[];
{
struct stat buf;
stat(argv[1], &buf);
printf("The file size are: %ld\n", buf.st_size);
printf("The file inode are: %ld\n", buf.st_ino);
}
Cheers
Rajeev
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP