pls correct my syntax.

Moderators: 666philb, Forum moderators

Post Reply
boof
Posts: 587
Joined: Sat Aug 15, 2020 9:17 am
Been thanked: 8 times

pls correct my syntax.

Post by boof »

I'm trying to invert my eth0 status with a shortcut key <F11>.
code:
!#/bin/sh
if ((ip a show eth0 up)!=NULL); (ifconfig eth0 down); (ifconfig eth0 up)

williams2
Posts: 1070
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 306 times

Re: pls correct my syntax.

Post by williams2 »

Something like:

Code: Select all

#!/bin/sh
if ifconfig | grep -q ^eth0
then
  ifconfig eth0 down
else
  ifconfig eth0 up
fi

If you are using JWM window manager, you should probably use jwmdesk to configure F11 to execute the script. (note: scripts have not been tested)

You really should determine what causes the slow down,
eg not enough ram, or fast transfer of data to/from an ntfs file system, which can load the cpu.
Different causes might require different solutions.

If you want to keep the network up, for example, to keep access to a network printer, it could probably be blocked blocked another way, for example, using the iptables firewall.

Starting Libreoffice'ss word processor like this might do what you want. Or not.

Code: Select all

ifconfig eth0 down
swriter
ifconfig eth0 up

A script like this could disable the network if the cpu load is more than 2.0

Code: Select all

#!/bin/sh
while true
do
  uptime | awk '{exit $8>1.8}' && ifconfig etho down
  sleep 60
done

This script does not automatically bring eth0 up again.
And it does not test whether eth0 is already down.
The awk command gets the pu load average for the last minute,
so there is no point in sleeping less than 60 seconds.

Last edited by williams2 on Tue Sep 20, 2022 8:06 am, edited 1 time in total.
Clarity
Posts: 4321
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1875 times
Been thanked: 581 times

Re: pls correct my syntax.

Post by Clarity »

It can all be done using "ip" command. See reference use here.

boof
Posts: 587
Joined: Sat Aug 15, 2020 9:17 am
Been thanked: 8 times

Re: pls correct my syntax.

Post by boof »

thanks william 2
that works fine.

nb
RAM now at 4GB, swapfile at 512MB. things much better, but freezes still happen. computer inadequate.

Clarity
Posts: 4321
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1875 times
Been thanked: 581 times

Re: pls correct my syntax.

Post by Clarity »

@boof I see your PC's post. This may not change things, as you may be having some hardware issue(s) causing your problem. BUT, I offer this info: It has always been recommended to use a SWAP partition/file that "mirrors" RAM...at a minimum. Thus, you might consider increasing your SWAP size to 4GB.

Since 3.5 decades ago, I use SWAP partitions on EVERY Unix/Linux setup ever done for several reasons from lab tests done back then. Modern operating systems benefit from these SWAP/PAGING layouts.

AND, I would NEVER put a SWAP on a USB stick!!! Thus your PCs system drive or on the fastest HDD/SSD/Raid drive you have connected to your platform would yield your best outcome.

If you find this helps, run with it.

williams2
Posts: 1070
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 306 times

Re: pls correct my syntax.

Post by williams2 »

4 GB should be adequate for most programs.

You can check the cpu usage by running something like
mpstat 60 >/tmp/iostat.log or iostat[ 60 >/tmp/iostat.log
the 60 is to print every 60 seconds.

If you want to see which processes are using the most cpu power, you can use top.

top -c -b -o +%CPU -n 10 >/tmp/top.log

or

top -c -b -o +%MEM -n 10 >/tmp/top.log

It can all be done using "ip" command

@Clarity Yes, ip is the newer one, ifconfig is depricated, but it still works.

Post Reply

Return to “Fossapup64”