HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Converting Kshell to C language
Operating System - HP-UX
1833871
Members
1656
Online
110063
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
02-22-2005 11:39 AM
02-22-2005 11:39 AM
Converting Kshell to C language
I have gotten this written in korn shell, can anyone give me some guides onto how to covert this to C language. I am particularly interested in how to move files efficiently using C under shell environment. :
#!/bin/ksh
# -- Date initialisation --
YY=`date +%Y`
MM=`date +%m`
DD=`date +%d`
HH=`date +%H`
MI=`date +%M`
SS=`date +%S`
# -- Files & Directories Initialisation --
DIR=/users/tester/temp
SCP=$DIR/T1
OCP=$DIR/Temp
FIL=$DIR/file.txt
OFL=$DIR/file_old.txt
NFL=$DIR/file_new.txt
LOG=$DIR/events.txt
TM1=$DIR/tmp1.txt
TM2=$DIR/tmp2.txt
#Check file modification status
ls -lt $FIL > $NFL
diff $NFL $OFL > $TM1
wc -l $TM1 > $TM2
No=`awk '{ print $1 }' $TM2`
cp $NFL $OFL
#NOW=`date`
if [ $No -gt 0 ]
then
#-- Log event --
echo "Change in Tester Deskew file detected, program ran on $YY$MM$DD at $HH$MI$SS""hrs" >> $LOG
echo "file modified on $NOW"
cp $SCP/* $OCP
rm -f $SCP/*
# -- Housekeeping --
if [ -f $TM1 ]
then
rm $TM1
fi
if [ -f $TM2 ]
then
rm $TM2
fi
if [ -f $NFL ]
then
rm $NFL
fi
#!/bin/ksh
# -- Date initialisation --
YY=`date +%Y`
MM=`date +%m`
DD=`date +%d`
HH=`date +%H`
MI=`date +%M`
SS=`date +%S`
# -- Files & Directories Initialisation --
DIR=/users/tester/temp
SCP=$DIR/T1
OCP=$DIR/Temp
FIL=$DIR/file.txt
OFL=$DIR/file_old.txt
NFL=$DIR/file_new.txt
LOG=$DIR/events.txt
TM1=$DIR/tmp1.txt
TM2=$DIR/tmp2.txt
#Check file modification status
ls -lt $FIL > $NFL
diff $NFL $OFL > $TM1
wc -l $TM1 > $TM2
No=`awk '{ print $1 }' $TM2`
cp $NFL $OFL
#NOW=`date`
if [ $No -gt 0 ]
then
#-- Log event --
echo "Change in Tester Deskew file detected, program ran on $YY$MM$DD at $HH$MI$SS""hrs" >> $LOG
echo "file modified on $NOW"
cp $SCP/* $OCP
rm -f $SCP/*
# -- Housekeeping --
if [ -f $TM1 ]
then
rm $TM1
fi
if [ -f $TM2 ]
then
rm $TM2
fi
if [ -f $NFL ]
then
rm $NFL
fi
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2005 12:35 PM
02-22-2005 12:35 PM
Re: Converting Kshell to C language
To me, it appears that the job you want to do is
best handled by using shell script. But if you must
write a C program for this, here are the library
routines you should be looking at:
Date initialization: see library routines
gettimeofday(2), time(2), ctime(3C) and related
functions (all listed in the manpage of ctime(3C)).
File modification status: Should use fstat(2) call. See
the manpage for more details. Structure stat
(defined in sys/stat.h) stores the access details of
the files. Use difftime(3C) routine for time
difference.
Log event: If you want to log to /var/adm/syslog,
then use syslog(3C).
Housekeeping: Use link(2), unlink(2) to copy and
remove files.
Does that answer what you are looking for?
- Biswajit
best handled by using shell script. But if you must
write a C program for this, here are the library
routines you should be looking at:
Date initialization: see library routines
gettimeofday(2), time(2), ctime(3C) and related
functions (all listed in the manpage of ctime(3C)).
File modification status: Should use fstat(2) call. See
the manpage for more details. Structure stat
(defined in sys/stat.h) stores the access details of
the files. Use difftime(3C) routine for time
difference.
Log event: If you want to log to /var/adm/syslog,
then use syslog(3C).
Housekeeping: Use link(2), unlink(2) to copy and
remove files.
Does that answer what you are looking for?
- Biswajit
:-)
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
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP