Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
How do I get this to send time to file every 10 seconds ?
Quote:
#!/bin/bash
#
# Send date/time to file every 10 seconds
#
count=5
if [ $count == 5 ]
then
sleep 10
date "+ %m/%d/%y %r" >> date.txt
else
echo "Has not been 10 seconds"
fi
This is a latter edition that does something useful.
I will study your suggestions.
Quote:
#!/bin/bash
#
# Linux Puppy 6.3.0 SiegeWorks 2016 A.P.K.
#
# Send CPU temps to file every 15 minutes
# NOTE: This messes with icon for CPUtemp
count=1
done=0
while [ $count -le 10 ]
do
(( count++ ))
if [ $count == 5 ]
then
continue
fi
date "+ %m/%d/%y %r" >> ~/Documents/CPU_TEMPS.txt
sensors -f >> ~/Documents/CPU_TEMPS.txt
sleep 900
done
Maybe I'm missing something, but why is this script so complicated? The "done" variable is never used, and what's the point of "count" causing the script to randomly skip the date/sensors part of the code on the 4th iteration of the while loop?
What was wrong with the original one? Why can't you just do:
#!/bin/bash
#
# Linux Puppy 6.3.0 SiegeWorks 2016 A.P.K.
#
# Send battery state to file every 15 minutes
# Useful in determining how long your battery will actually last
#
count=1
done=0
while [ $count -le 10 ]
do
sleep 1
(( count++ ))
if [ $count == 5 ]
then
continue
fi
date "+ m/d/%y %r" >> Battery_State.txt
grep remaining /proc/acpi/battery/*/state >> Battery_State.txt
#
grep full /proc/acpi/battery/*/info >> Battery_State.txt
#
grep charging /proc/acpi/battery/*/state >> Battery_State.txt
sleep 900
done
Again, you need to tell us what it is you're trying to do. Posting random code samples with NO explanation of what it's doing, what you expect it to be doing, what's good/bad about it, etc. is pointless.
Cron is one of the least complicated parts of Linux. You tell it when to run and what to run, what's complicated about that?
Last edited by suicidaleggroll; 01-13-2016 at 10:47 AM.
Sounds like a pain to me, having to manually run it every time...
Either way, it sounds like you just need to get rid of that if statement that's checking count, it doesn't seem to serve any purpose.
Code:
#!/bin/bash
count=1
while [ $count -le 10 ]; do
(( count++ ))
date "+ m/d/y r" >> Battery_State.txt
grep remaining /proc/acpi/battery/*/state >> Battery_State.txt
grep full /proc/acpi/battery/*/info >> Battery_State.txt
grep charging /proc/acpi/battery/*/state >> Battery_State.txt
sleep 900
done
It would be simpler to just let it run all the time, automatically. Is there any particular reason you don't want it running all the time?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.