Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i am checking filesystem using chkfsys utility . this utility return zero(0) if filesystem is good. sometimes chis utility taking more time if error occured in filesystem .
so i have to check filesystem. if it will return the value less then 5 sec i have to return 0 else return 1.
i have to write this in shell script please help me .
I'm not sure that I agree with the reasoning that because a command is taking long there must be a problem with the filesystem, but don't know enough about what you're doing to really form an opinion about that.
Regarding how to time a command and return a value based on that, something like this should do:
Code:
#!/bin/bash
## time a command
# Remember start time
starttime=$(date +"%s")
# Place your command here, instead of my "sleep" command
sleep 1
# Remember end time
endtime=$(date +"%s")
# Calculate elapsed time
(( elapsed = endtime - starttime ))
# Display result - for debugging - optional
echo $elapsed
# Return exit status depending on time
if [ $elapsed -lt 5 ]
then
exit 0
else
exit 1
fi
you might be able to use the "time" command for this. For example something like
Code:
#!/bin/bash
# Don't use shell built in time, because we want to format the output
# Redirection gymnastics because the output is to stderr
tfloat=$(/usr/bin/time -f %e chkfsys 2 2>&1)
# Strip off the decimal part so we can use integer comparison
tint=${tfloat%.*}
# Do the comparison
if [ $tint -lt 5 ] ; then
exit 0
fi
exit 1
#!/bin/bash
chkfsys &
sleep 5
pkill chksfys
if [ "$?" = "0" ] ; then # chksys was killed
exit 1
fi
exit 0
Note that this will kill all running chkfsys processes that the user has permission to. Also note, that like cliffordw, I really wonder if you are using the right approach here.
you need to start two processes, the first one will run chkfsys and the second one will kill it after the specified timeout. but actually it has no meaning, if chkfsys waits for user input it will fail anyway (because you will kill it)....
actually i have four partition in my CF(hd0t77,78,79,8) . filesystem corrupted may happen any partition. i have to check the all partitions . i checked the 4 partition first two partitions filesystems are good .third partitions is problem .so i have to find which partitions is good ,which partition is bad.
actually i have four partition in my CF(hd0t77,78,79,8) . filesystem corrupted may happen any partition. i have to check the all partitions . i checked the 4 partition first two partitions filesystems are good .third partitions is problem .so i have to find which partitions is good ,which partition is bad.
Ok...so show us what YOU Have written/tried to fix this problem. So far, you've had others write your script for you, and shown no effort of your own.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.