Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's 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.
sumeet inani: this is great, although I suggest /tmp/int.txt instead of ~/int.txt, since any good desktop distro will wipe out /tmp at each boot, unless you want it to be persistent and user specific, in which case I would suggest to name your file ~/.int.txt so it doesn't appear in nautilus. Check if the file exist and create it with 0 if it does not.
An interesting perspective; do you have any references to support it?
I have not meant it as an absolute. There are WM's with much lesser requirements, but if you compare two mayor WM's, KDE and GNOME, you must agree that GNOME project is striving to minimalistic design as much as possible. Of course, with new powerful hardware and average hardware replacement cycle of 3-5 years, they allow larger and large requirements, but I still believe withing lower standards.
I have not meant it as an absolute. There are WM's with much lesser requirements, but if you compare two mayor WM's, KDE and GNOME, you must agree that GNOME project is striving to minimalistic design as much as possible. Of course, with new powerful hardware and average hardware replacement cycle of 3-5 years, they allow larger and large requirements, but I still believe withing lower standards.
Thanks DrLove73 IDK KDE but am happy to take you at your word -- that in a field of Gnome and KDE, Gnome is the lighter.
To agrouf
I want to store variable in file permanently so that even after shutdown when I reboot I will get next wallpaper.I don't like random function because there are chances of repeat & to prevent repeatition script will become complicated
But my query still remains unsolved
i will reiterate my method
integer variable's value is stored in file so that its value will be permanently stored.
~/.int.txt(created by us before putting script in cron) initially contains 0[improved filename suggested by agrouf]
In our script
variable i takes its value from file int.txt & sets the wallpaper to ~/wp/0.jpg
Now increment i.
(i+1) >~/.int.txt --note we are not appending value of i but overwriting int.txt file with next value.
In beginnning of script there will be condition
if(i>=99)
i=0;
so we can have 99 wallpapers.
My problem is which command to use to give a file as input to integer variable.
Can somebody write the script ?(because I am beginner so don't know much though I am reading tutorials to get a grasp)
Last edited by sumeet inani; 12-21-2009 at 10:52 PM.
to isolatedsh33p
In your case the script is running in background all the time ( when wallpaper is not being changed then it is sleeping ) while what I propose is that crontab will execute script to change wallpaper at regular intervals while in between two intervals script is not present in memory .
I think
i think that if variable's value is stored in file then its value will be static.
i mean
Suppose ~/int.txt initially contains 0
In our script
variable i takes its value from file int.txt & sets the wallpaper to ~/wp/0.jpg
Now increment i.
(i+1) >~/int.txt --note we are not appending value of i but overwriting int.txt file with next value.
In beginnning of script there will be condition
if(i>=99)
i=0;
so we can have 99 wallpapers.
What do you say ?
I don't know much scripting so please help ?
I never used crontab before, that's why I used loop. Anyway, how about this
Code:
i=`head ~/.int.txt` #get the content of the file
#if greater than 99, then sets back i to 0.
if [ $i -gt 99 ]; then
let i=0
fi
wp_fn=$HOME/wp/$i.jpg #set the name of the wallpaper file
... Do commands to change the wallpaper ...
#after finished, increment the value of i
let i=i+1
#finally write it into int.txt
echo "$i" >~/.int.txt
If you figure out how to use crontab, please share the knowledge with me.
Last edited by isolatedsh33p; 12-22-2009 at 12:17 AM.
one mistake in your script
Also first line of script should be
#!/bin/bash
without this let i=i+1 gave error
what i liked is you have used $HOME so it becomes independent of username.
i think we could also do
wp_fn=~/wp/$i.jpg isn't it ?
i didn't notice any increase in memory utilization while script ran.
About crontab
Create job.cron file containig following
0,5,10,15,20,25,30,35,40,45,50,55 * * * * ~/wp-change-script
brief explanation
0,... are minutes here I have changed every 5 minutes(allowed values 0 to 59)
The * represent all values for hour(o-23),day of month(1-31),month(1-12) & day of week(1=monday to 7) respectively.
add the file to task scheduler using
crontab job.cron
and verify it using
crontab -l
NOTE that you should create an empty file /usr/lib/cron/cron.deny(from root) so that all users are allowed.
Question 1)can we output cpu usage pertcentage to a file for few minutes ?
Question 2)How can we add 'check if ~/.int.txt exists otherwise create it' to script ?.
Last edited by sumeet inani; 12-22-2009 at 09:28 AM.
I don't like random function because there are chances of repeat & to prevent repeatition script will become complicated
Well, it's a little more complicated but if you want to raise the challenge, there is a way to do that.
Basically, you setup a list of files and you randomly swap each element one by one. You can then use the random list and be sure no element is repeated in that list.
Anyway, even if you don't use random numbers, having a list of files may be handy if you don't want to have a special name for your files ($n.jpg) You could use any file that is in the $HOME/wp directory, even recursively.
Quote:
Originally Posted by sumeet inani
About crontab
Create job.cron file containig following
0,5,10,15,20,25,30,35,40,45,50,55 * * * * ~/wp-change-script
Actually, you can use this simpler syntax:
*/5 * * * * ~/wp-change-script
It means every 5 minutes.
You can also use the crontab -e command to edit the crontab.
Quote:
Originally Posted by sumeet inani
Question 1)can we output cpu usage pertcentage to a file for few minutes ?
You can get cpu usage with /proc/loadavg: http://www.redhat.com/docs/manuals/e...c-loadavg.html
I don't think it will be affected by your script at all though. Your script asks gnome to load images from the disk. most of its time will be spent waiting for the disk, idle (unless you have very fast SSD)
Quote:
Originally Posted by sumeet inani
Question 2)How can we add 'check if ~/.int.txt exists otherwise create it' to script ?.
Code:
if [ -e ~/.int.txt ]; then
#do something
else
#do something else
fi
I mean in random how can we make sure that all files become wallpaper before repetition occurs ?
I think Suppose we pull out lines from ~/wp/link.txt where each line has path address of desired image.
I think for avoiding repetition we have to maintain atleast two arrays one of which contains file that have become wallpapers.Isn't it ?.Presently my level is amateur so too difficult for me.First i have to learn basics.Even this script written by isolatedsh33p.
I have noted that in ubuntu 9.04 the script does not change wallpaper.though the number in .int.txt was changing.
Why is that ?
Last edited by sumeet inani; 12-22-2009 at 09:38 AM.
I ran
gconftool-2 -g /desktop/gnome/background/picture_filename
It stays at ~/wp/0.jpg
though
cat ~/.int.txt
7
This is puzzling because same script works well in ubuntu 8.04 & here it seems .int.txt gets edited but string does not.Also I checked mail then got no error message.
Can anybody spot error in script presented by isolatedsh33p ?(the first line should be #!/bin/bash already pointed out)
Last edited by sumeet inani; 12-23-2009 at 02:44 AM.
yes in terminal
As son as i execute script wallpaper changes but when I put it in cron then .int.txt changes but string does not & hence wallpaper does not.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.