LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 06-20-2006, 03:58 AM   #1
squirrel001
Member
 
Registered: Feb 2006
Posts: 51

Rep: Reputation: 15
help me to write wget commnad in .bash_profile


i've changed the .bash_profile file so that everytime i logon to my pc it starts to download file using wget. now the problem is if i logoff and then again logon, another instant of wget starts running and if i logoff and logon several times, i see several instances of wget running (by <ps -A> commond). help me to write a code so that it would check first if any instances of wget is running and if no instances of wget is running only then it will run an instance of wget and starts downloading. i'm not root. please help.

thanks
 
Old 06-20-2006, 04:06 AM   #2
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Try something like:
Code:
ps -efl | grep wget
RETVAL=$?
if (( $RETVAl == 1 ))
   #no running copy of wget found, so launch it
   wget ...
elif (( $RETVAL == 0 ))
   #running copy of wget found
else
   #grep returned "2", indicating an error => may be worthwhile to alert you somehow
fi;
Of course, you may need to fine-tune the "ps" command (ie only look for processes owned by your user, etc).

An alternative and commonly used approach is storing a lock-out file in /var/run.
In your case (non-root), you'll need root access to create a subdirectory under /var/run you can write too. /var/run itself is usually writable only by root.
Your code would then look something like this:
Code:
if [[ -f /var/run/your_dir/wget_lock_file ]]; then
   #file exists, so wget is assumed to be running
else
   #no lock file, so wget shouldn't be running
   touch /var/run/your_dir/wget_lock_file; #create lock file, to lock out future wget calls
   #call wget
   wget ...
fi;
 
Old 06-20-2006, 04:23 AM   #3
squirrel001
Member
 
Registered: Feb 2006
Posts: 51

Original Poster
Rep: Reputation: 15
thanks a lot sir
my administrator is not flexible enough to give me a directory in /var/run, so i'm in need of taking ur first method. thanks again, i badly needed it.

another question (if u don't mind):

let me clarify: whenever i turn on my pc an login screen comes. is it possible that wget will start running whenever the login screen comes? (i mean i haven't logged in yet). if the answer is no, is there any process that i can automatically remotely login (giving automatically the login name and password) to my desired computer using my working place's computer (all the pcs are in a single lan).
thanks a lot
 
Old 06-20-2006, 05:37 AM   #4
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
The answer is "yes".
There are multiple ways to launch programs during the start up sequence.
Launching them after you login (by putting it in your bash_profile or .bashrc) is just one possibility.
For instance, you can automatically launch programs:
* anytime anyone logs in (put it in /etc/profile, /etc/bashrc, etc),
* whenever your X windows, KDE (or other window manager) starts (search this forum),
* as a background service (ie whenever your system changes it's runlevel).
Check out "man init" for info on runlevels, "man chkconfig" and maybe also "man service".

The exact solution you'll need depends on:
-your Linux distribution (please post it and/or add it to your user profile here on LQ forum)
-in which case you want to start it.

For starters, put the code you have so far in a separate file and add
#!/bin/bash
at the top of this file. Then give the file "execute" (x) permission for you and you have created a Bash script that can easily be called.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
source code of fdisk commnad arunka Programming 1 03-05-2006 11:10 PM
.bash_profile UmneyDurak Linux - General 1 10-18-2005 12:44 AM
locate a commnad zchoyt Linux - Software 7 04-14-2005 03:18 PM
.bash_profile praveenv Linux - Newbie 3 08-14-2004 01:58 PM
Does Slackware have "lndir" commnad? buboleck Linux - Newbie 2 12-23-2003 01:05 PM


All times are GMT -5. The time now is 10:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration