Results 1 to 6 of 6
On my laptop, when I close the lid it goes into hibernation. When I reopen the lid, I am no longer connected to the internet. I am currently fixing this ...
- 06-07-2007 #1Just Joined!
- Join Date
- Jun 2007
- Posts
- 9
Help with bash script
On my laptop, when I close the lid it goes into hibernation. When I reopen the lid, I am no longer connected to the internet. I am currently fixing this problem using the following
script.
rm /etc/dhcpc/dhcpcd-eth0.pid; dhcpcd
This works very well except that after a few times of doing this, I have dhcpcd running on a bunch of different processes. So, I started working on a new script. I'm pretty new to linux and bash and I can't figure out why this script won't run. It throws a syntax error near unexpected token ';'. Any help would be great, and thanks in advance. The following is the new script.
rm /etc/dhcpc/dhcpcd-eth0.pid;
ps > txt.txt;
grep dhcpcd txt.txt > txt1.txt;
cut -c1-5 txt1.txt > txt2.txt;
rm txt.txt txt1.txt;
for i in $(cat txt2.txt);
do kill $i;
dhcpcd
- 06-07-2007 #2
I think it's because you forgot to include a "done" after your "do".
Registered Linux user #388328 || Registered LFS user #15880
AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 9400 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
Need instant help? Try us on IRC -- #linuxforums on freenode
- 06-07-2007 #3
Just to let you know that you can compress a lot of this. For example,
Could becomeCode:ps > txt.txt; grep dhcpcd txt.txt > txt1.txt; cut -c1-5 txt1.txt > txt2.txt;
That will strip out any processes running that include the word "dhcpcd" but *not* the word "grep", print the second word on that line (i.e. the pid), and dump it to txt2.txt.Code:ps aux | grep dhcpcd | grep -v grep | awk '{print $2}' > txt2.txt
EDIT: You could even include all that (without "> txt2.txt" of course) inside the brackets like this,A one line bash-script!Code:for i in $(ps aux | grep dhcpcd | grep -v grep | awk '{print $2}') ; do kill $i ; done
Registered Linux user #388328 || Registered LFS user #15880
AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 9400 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
Need instant help? Try us on IRC -- #linuxforums on freenode
- 06-08-2007 #4Linux User
- Join Date
- Aug 2006
- Posts
- 458
here's another version
Code:ps aux | awk '/dhcpcd/{print $2}' | xargs kill
- 06-08-2007 #5Just Joined!
- Join Date
- Jun 2007
- Posts
- 9
Thanks for the replies, I got it working.It was because of the missing 'done'. Thanks also for the other examples. I am pretty new to bash so I will definitely check them out to see what makes them tick! Thanks alot!
- 06-08-2007 #6Registered Linux user #388328 || Registered LFS user #15880
AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 9400 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
Need instant help? Try us on IRC -- #linuxforums on freenode


Reply With Quote
