Some good bash and bash alias tricks.

Share your own howto's etc. Not for support questions!

Some good bash and bash alias tricks.

Postby Deb-fan » 2020-09-08 19:02

Welcome to this edition of fun with bash, bash aliases and how to run scripts via a bash alias. Also some fun with file managers is going to be thrown in too. In my case that's usually Thunar but any other file manager will do here.

Okay description of problem, I have some files I often edit and navigating to them in ie: Thunar was getting to be a real PITA, now I could've symlinked to them in any convenient location(s) and still might but what happened to pop into my head was why not use a bash alias for it, so this is the result.

Couple of prelims, you can add bash aliases to your .bashrc file kept in your users /home directory in the appropriate section of the file, however if you don't already have one let's create a dedicated file to store bash aliases (if you don't already have such a file), create a normal text file in your /home, name it .bash_aliases ... There is nothing special needed here, the syntax goes as follows, add as many aliases as you like and I encourage comments to tell yourself what the alias is/does too, here's a snippet from mine to demonstrate.

Code: Select all
# Check the systems current clock, top is cpu0, bottom cpu1
alias freq="cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq && cat /sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq"
# Quick way to edit a file I use often.
alias tweak="/bin/bash ~/.bin/edit2.sh"
# Running a script from ~/.bin to edit a file.
alias patch='/bin/bash ~/.bin/edit.sh'
# This one is to open thunar in a directory I use often.
alias quick="/usr/bin/thunar /mnt/data/.directoryname/.blahblah/newstufftosave &exit"


That's all there is to it, the lines starting with # Are comments, bash doesn't care about them, they're there to let me know what and why I added that alias, otherwise the line beginning with alias is what's significant.

# Comment tell yourself what the alias is for or etc.
alias youralias="what-you-want-bash-to-do-when-you-type-that-alias-in-terminal"

Enclosed in "quotes" ...

Some of those are the ones I'm wanting to demonstrate here, such as alias patch="/bin/bash ~/.bin/edit.sh"

Notes: When I type the word patch into a terminal, what it does, the bash shell (which is the default user shell in a massive number of gnu/Nix distro's, including Debian(+based)then runs the designated script this ~/ is a shortcut for and just the same as typing out /home/yourusername ... In my case I have a directory named .bin in my users home, it's a .(dot) directory and that just means when you create a directory you name it with a .(dot) in front of it ie: .mydotdirectory, I like to use .directories because they aren't visible unless you unhide them, thus they don't clutter up the /home directory.

Anyway getting back to it, in that .bin directory I created a script, just a regular txt file. (end it with) the .sh extension, for shell. Here's the contents of the edit.sh file ...

Code: Select all
#!/bin/bash
/usr/bin/leafpad /mnt/data/.directoryname/.blahblah/newstufftosave/patches &exit


Begin the file with the proper shebang #!/bin/bash for a bash script, though for any script start the thing correctly. What the rest of it does, /usr/bin/leafpad is the path to the leafpad text editor binary, I could've gotten away with just leafpad or gedit or geany of whatever but whatever, what follows that is the path to the file I want to open and edit in leafpad and the &exit(probably not necessary) but that tells bash to close. So to this point, when I type "patch" in a terminal, it runs the script in ~/.bin/edit.sh, which launches leafpad and tells it which file to open and that's what it does for me. One last VERY important part of dealing with shell scripts, make them executable with "chmod +x /path/to/scriptname.sh" in my case "chmod +x ~/.bin/edit.sh" Though you can do this in a graphical file manager, can open a terminal here in tha same location as the script etc. Also note DO NOT use sudo when dealing with files or scripts-etc in your users /home, your user already owns those and mucking around in your /home files with elevated priv's like as root/sudo can cause problems, easily solved but still ... standard warning.

When I run that alias "patch" the file I want to open, opens in the selected editor and then returns the cmd prompt to my terminal/shell for me. So it's ready to take further input. The edit2.sh is also a script which does the same for another file I often end up opening/editing.


Next up this one ... Same deal, there's a directory I often end up navigating to in my file manager and click, click, clicking the way into it gets tedious quick(even named the alias quick for it.) So this opens the directory I want in my selected file manager.
Code: Select all
# This one is to open thunar in a directory I use often.
alias quick="/usr/bin/thunar /mnt/data/.directoryname/.blahblah/newstufftosave &exit"


Again surely could've just used simply "thunar" instead of path to the binary but again ... whatever. I could've created another script to do the same with thunar as was done with leafpad and the file I want to open/edit and it's easily enough done if you wanted but all this one does is launch thunar and opens it in the directory I want it to open in, that could be anywhere ie: /usr/share or / < (for opening it in the root directory.) and the &exit closes the terminal/shell. These puppies can also of course be used in keybinds(keyboard shortcuts), menu entries, icons, panel launchers or whatever else too. Any and/or every desktop or window manager should have easy means of setting up such things and the cmds you'd use are the same-similar. You should get the general idea ...

Other bash alias related stuff:

Just edit that .bash_aliases file whenever you want to add a new alias, note that they won't take effect in a given terminal, until you close + re-open the thing, so the new aliases are recognized(the .bash_aliases file gets sourced again.) Also at times it's easy to forget what aliases a person has set, to see a list of the puppies just type "alias" in a terminal and it'll list them out, though without the comments, to see those use "cat .bash_aliases" to get the full contents of the file, including comments OR setup an alias to check the contents of "cat .bash_aliases". :P
Last edited by Deb-fan on 2020-09-10 03:09, edited 1 time in total.
Most powerful FREE tech-support tool on the planet * HERE. *
Deb-fan
 
Posts: 889
Joined: 2012-08-14 12:27

Re: Some good bash and bash alias tricks.

Postby sgosnell » 2020-09-08 23:23

If you don't want to close the terminal after editing your alias file, you can do either of these:
Code: Select all
source .bash_aliases
source .bashrc
.bashrc reads .bash_aliases automatically each time it's started or sourced.
sgosnell
 
Posts: 780
Joined: 2011-03-14 01:49

Re: Some good bash and bash alias tricks.

Postby sickpig » 2020-09-08 23:32

sgosnell wrote:you can do either of these:

Or just do
Code: Select all
. .bashrc
. .bash_aliases
User avatar
sickpig
 
Posts: 474
Joined: 2019-01-23 10:34

Re: Some good bash and bash alias tricks.

Postby Deb-fan » 2020-09-09 20:41

Appreciate the adds fellows. :)
Most powerful FREE tech-support tool on the planet * HERE. *
Deb-fan
 
Posts: 889
Joined: 2012-08-14 12:27

Re: Some good bash and bash alias tricks.

Postby Deb-fan » 2020-09-11 16:08

Okay, well ... this is still fun with bash + bash aliases and also involves running a script with an alias, so putting it up here. :D

In another tute, figured out a way to auto run a script when a usb thumb drive is un/plugged by using a udev rule and started messing around with ways to get it to automatically run a bash script that will rsync the contents of a target directory to that thumb drive, while I'm still working on it and may get there someday, cooked up something that's worth sharing on the topic.

Was getting real frustrated with the situation, playing around with a bash script (and my bash skills suk!) The stupid needing priv's to even mount the usb drive, this that ... other BS !!! ARGHHHH ! So googled, came across a common sense suggestion, if you're going to use sudo cmds in a script, why not just run the script with sudo ie: "sudo /path/to/scriptname.sh". Yep ... not bad as privileged commands in it are all run with priv's, this would mean only having to enter password the one time. This however isn't what I wanted, fortunately am aware of a cool nix trick for this. A person can create a file at the following, /etc/sudoers.d and enter commands they wish to run as sudo but w/o password, clearly this is to be used with common sense and caution. Anyway ... I created a file there named myrules and added this as what's relevant to what's being discussed here.

Code: Select all
# Stuff I don't want to enter passwd to run/use.
yourusername ALL=(ALL) NOPASSWD: /usr/local/bin/backup.sh


Edit: Had to correct an oversight in the example of the /etc/sudoers.d/myrules file. Dang it, example is good to go now. Though this is one of the reasons I keep a root user acct around. Syntax mistakes in those sudoers.d files or if someone messes up the /etc/sudoers file itself with direct editing can break sudo, sudo cmds won't work and that can leave someone in a bad situation if they don't know how easy it is to fix. aka: Chroot an ailing system from live session and fix it.

In my case, with a root user, even if sudo gets borked, I just have to "su -" login as root and then can quickly fix such a syntax error to restore sudo. So if I'm in a hurry and break sudo by making a mistake in such a file, takes less than 1min to fix it. So I quit worrying about visudo long ago. While doing this edit may as well do it right, actually these files are supposed to be edited by using visudo. An example of doing that here would be "sudo visudo -f /etc/sudoers.d/myrules" it'll open that file using visudo, then if I change it and have messed up syntax, put a comma in the wrong place etc etc, when I go to save the file visudo will tell you there's a problem. Someone can just back-out of applying the changes, like closing the terminal or whatever w/o those errors being written. Google if you desire further info on using visudo and about sudoers.d.


Of course you can add more, just separate them adding a ,(comma)to the end of the last entry, then a space and add the next, no comma at the end/last one needed. What the above does is let me run the following in terminal w/o passwd needed "sudo /usr/local/bin/backup.sh" Next up we need a backup.sh file (a script) at that location, let's make it, in terminal "sudo touch /usr/local/bin/backup.sh" which creates that file, then "sudo chmod +x /usr/local/bin/backup.sh" makes it executable and from here would say open the file in a graphical text edit with sudo/root priv's so you can copy/paste what's coming up. Wait a minute before doing that.

Couple other things first, we're going to create a mount point to mount the thumb drive to when the script is run, do so with "sudo mkdir -p /mnt/usb" it creates a directory at /mnt/usb which is going to be the mount point used for this, of course peeps are free to use another location-name etc. Though /mnt is totally appropriate for this type of thing.

Plugin the thumb drive you wish to use here, we need to get the UUID of the partition on it we're going to use in the script, that's persistent across reboots, get this info by running "sudo blkid" take note of the UUID needed. In my case that's sdc1, the 1st partition on the thumb drive. ie:

Code: Select all
/dev/sdc1: UUID="7a04842f-2005-26cd-8489-09c437d410ac"


Getting there, now for opening the backup.sh script as sudo/root, in a graphical editor or command-line editor if you like ... Here's my script contents by way of example.

Code: Select all
#!/bin/bash
sudo mount -t ext2 /dev/disk/by-uuid/7a04842f-2005-26cd-8489-09c437d410ac /mnt/usb

sudo -u yourusername rsync -aAX /mnt/data/newstufftosave/ /mnt/usb/test/

sudo umount /dev/disk/by-uuid/7a04842f-2005-26cd-8489-09c437d410ac ;

exit


Gawd, now have to explain all that, 1st off something of note in the beginning of it, the "mount -t ext2" that's because my thumb drive is formatted as ext2, because it respects gnu/Linux file permissions etc etc. Now you likely have a fat32 formatted usb drive which is fine too, use "mount -t auto" instead of what I've got. /dev/disk/by-uuid/YOURUUID is where the script is targeting the usb drives partition I'm using here, plugin your drive, open a file manager and click your way into that location, you'll find your thumb drive there, though with its UUID, not mine or the one I'm using in the example above.

You can unmount and remove your thumb drive a bunch of times and check again, n again n again etc. Try some different usb ports too. Yep you'll notice your thumb drive keeps popping up there and its UUID is the same, now getting back to it ... That first line is just mounting the thumb drive based on its UUID to the chosen mount point = /mnt/usb the next line is important (for me, as again I'm using a filesystem which cares about ownership/permissions) the "sudo -u username" runs the rest of that, the rsync command as that user, so I don't have to worry about ownership-etc being changed to root when the stuff is copied by rsync to the thumb drive, in your case go ahead and use it, won't matter regardless, though not using it can depending on the filesystem you want to copy this stuff to, /mnt/data/newstufftosave/ is the source directory, it's where rsync is going to copy everything from and in my case /mnt/data is a shared ext4 data partition I've got setup to automount in /etc/fstab, again newstufftosave is just a directory on that shared data partition.

The destination directory is /mnt/usb/test/ a directory named test on the thumb drives partition, though actually rsync will create it for you w/o having to do so ahead of time. The IMPORTANT thing here is be sure you use the right paths for the source and destination. Shew, alright ... almost done, the "sudo umount" is just unmounting the thumb drive from /mnt/usb the ; is just like typing & and finally the next line ... exit, does that, exits the dang script. Clearly after you've changed things to fit your system, UUID, filesystem you're using, username etc. Save the backup.sh ... NOTE: See ps2 edit post below, if you're using fat32.


Last up here, time to add an alias, as outlined in the tute above this one, if you've got a .bash_aliases file in /home and the command-line text editor nano installed on your OS run "nano .bash_aliases" Otherwise open the .bash_aliases file with a graphical editor of choice, this is the alias I added.

Code: Select all
# Alias to rsync backup files to thumb drive.
alias usbbk='sudo /usr/local/bin/backup.sh'


And there you have it, in future, when I add or change files in that source directory, can just plugin my thumb drive, pop open a terminal and run the alias shown "usbbk" and rsync will dutifully copy stuff over to the thumb drive for me. WOOT ! Pretty cool stuff. Not quite as cool as all this happening automagically when a certain usb drive is plugged but none to shabby either. :)

Ps, Holy crap, gonna have to start putting chapters n page numbers in these monsters. There's another gd tute though. :P
Last edited by Deb-fan on 2020-09-14 01:18, edited 3 times in total.
Most powerful FREE tech-support tool on the planet * HERE. *
Deb-fan
 
Posts: 889
Joined: 2012-08-14 12:27

Re: Some good bash and bash alias tricks.

Postby Deb-fan » 2020-09-12 00:05

Ps2 edit:

Code: Select all
 
#!/bin/bash
sudo mount -t vfat /dev/disk/by-uuid/YOURUUIDHERE /mnt/usb -o umask=0000,uid=1000,gid=1000

sudo -u yourusername rsync -aAX /mnt/data/newstufftosave/ /mnt/usb/test/

sudo umount /dev/disk/by-uuid/YOURUUIDHERE  ;

exit


While does work when using "mount -t auto" initially on a fat32 formatted drive, was getting permission errors w subsequent rsync writes to the thing. So the above is the proper way to mount the thing for this, umask=0000 is basically saying everything is world writable etc, uid and gid is your user/group id, default user in so many things gnu/nix is user/group 1000. Though that info is easy enough to get for a-any given user on the system in a terminal too. Anyway there you have it, best use the above for the backup.sh script for use with fat32 formatted thumb drives. Okay am happy w this now. Still digging around on finding an automagic method, arghhh. :)
Most powerful FREE tech-support tool on the planet * HERE. *
Deb-fan
 
Posts: 889
Joined: 2012-08-14 12:27

Re: Some good bash and bash alias tricks.

Postby Deb-fan » 2020-09-12 21:28

Code: Select all
#!/bin/bash

# This is the entry for an ext2 formatted thumb drive.
if [ -e /dev/disk/by-uuid/YOUR-UUID-GOES-HERE ]; then
   sudo mount -t ext2 /dev/disk/by-uuid/YOUR-UUID-GOES-HERE /mnt/usb

sudo -u yourusername rsync -aAX /mnt/data/newstufftosave/ /mnt/usb/test/

sudo umount /dev/disk/by-uuid/YOUR-UUID-GOES-HERE ;

fi

# This is for a fat32 formatted thumb drive.
if [ -e /dev/disk/by-uuid/YOUR-UUID-GOES-HERE ]; then
   
   sudo mount -t vfat /dev/disk/by-uuid/YOUR-UUID-GOES-HERE /mnt/usb -o umask=0000,uid=1000,gid=1000

sudo -u yourusername rsync -aAX /mnt/data/newstufftosave/ /mnt/usb/test/

sudo umount /dev/disk/by-uuid/YOUR-UUID-GOES-HERE ;

fi

exit


Okay, went back to the drawing board, thought of "hey, must be fairly easy to run(source) a script from within a script", popped into my bean, yeah my current script obsession is getting out of hand apparently. :D

The above could be used for doing that too, though what I'm wanting to demonstrate with this is running the rsync operation for more than one thumb drive, based on whether they're plugged in or not. Obviously as shown these drives are formatted with different filesystems, one is ext2 ... the other fat32 clearly. Using the if statements in the script let's me target more than 1 thumb drive with the script, when the ext2 drive is plugged, a symlink for it's UUID is created in /dev/disk/by-uuid/ITS-UUID-HERE and that's what the bash script checks if either of the thumb drives UUID's or BOTH are there ... meaning the drives are plugged, when I use the alias I set in .bash_aliases as described above it runs the the script at /usr/local/bin/backup.sh and WHAM rsync does its magic. Also will do the backup to both of them, if both happen to be plugged in.

If neither drive were plugged in and used the bash alias, the bash script just exits. Even cooler and much cleaner than having to bother with making more than one script or adding a bunch of aliases for usb.drive-A, B and C etc. :)
Last edited by Deb-fan on 2020-09-14 01:28, edited 1 time in total.
Most powerful FREE tech-support tool on the planet * HERE. *
Deb-fan
 
Posts: 889
Joined: 2012-08-14 12:27

Re: Some good bash and bash alias tricks.

Postby Deb-fan » 2020-09-14 00:48

Had to do a correction on info related to sudoers.d above. Arghhhh fixed it though. :)

It's a dang good trick to know period. A lot of interesting uses for it. Now that I've cleared that file in my case that's /usr/local/bin/backup.sh so I can run privileged cmds in that script w/o entering a password, can use it for a bunch of useful things by doing similar to what's shown, using conditionals and if statements etc to only run(source) xyz-script or series of commands when the situation I'm going for matches it. All of which won't require entering a password. Also as shown a person can elect to run a particular part of a bash script as their normal user whenever appropriate too.

The adventure on this continues of course and as usual with almost anything gnu/Linux of course turns out there's an endless number of interesting/cool things related to doing something like automatically executing a script on plugging in a certain usb device. Fiddling around with a util included with udisks2 named udisksctl which can mount usb's and other stuff as user without need of passwd but so far it's finicky, really due to user ignorance at this pt, got it working but like the approach outlined above better. It's=udisksctl still cool and worth learning about. Turns out people can use stuff in a udev rule file now which will run a systemd service unit, thus it can execute a given script on a certain device un/plug too.

Haven't fully figured it out yet but apparently the RUN+= part of udev rules is often dirty/hacky, known to be misused and abused compared to using these newer systemd elements someone can use in a udev rule. Couple of those udev thingy's being ie: ...

TAG+="systemd"
ENV{SYSTEMD_WANTS}=="nameoffile.service"

Googling such is sure to bring up related info to this. At the moment I'm goodly and truly burnt out on screwing with this !!! Errrr ... actually was already that and more 12hrs ago !!! Still hopefully this inspires nixers and helps give them a leg up in learning this junk.
Most powerful FREE tech-support tool on the planet * HERE. *
Deb-fan
 
Posts: 889
Joined: 2012-08-14 12:27

Re: Some good bash and bash alias tricks.

Postby Deb-fan » 2020-09-14 08:22

Just more hair brained nixness wanted to share, also at this point these tutes are starting to bleed together and over-lap, junk from one could be very relevant to or supplement other how-to's but in one of these suckers noted an interest in running a bash script when a certain usb thumb-drive or device is plugged, this tute shows how to target however many usb-drives a nixer wants for doing a backup, using it's UUID in an if statement ... as demonstrated above but doesn't cover automagically doing so. Well using a crontab which executes this script however often someone wanted and set it to ie: Every 30secs or whatever, it's not going to add much, almost nothing by way of system overhead and in such a scenario, when one of the usb's I've setup to be included in the script is plugged, for as long as it's plugged, any new files or files I update-change in that source directory would be rsync'ed to the backup directory every 30secs. Rsync only writes the changes anyway, one of it's many AWESOME qualities obviously ...

Not doing a write up about the particulars of doing such, no doubt PLENTY of good one's easily found on the interwebz already. Setting up a crontab to run a script etc. Some obvious refinements present themselves, such as if that drive is already plugged, that could be used as the match vs mounting it at ie: /mnt/usb etc, if not, then the script could be told to yep, mount it there and perform the backup. Such a thing could complement some of the junk outlined in this thread though. Just wanted to share the general idea, as again ... It might motivate people to figure out how to do something cool and useful with their Debian gnu/Nixy goodness. :D

Ps, yet more nonsense, there's a golden principle for techies or should be and it goes as follows, "Thou shall not waste much time + effort reinventing the wheel, unless you're stupid or enjoy doing such." RAmennnnnnn, in other words there's TONS of scripts and scripting examples people have posted online, so search for those, learn from or use them for xyz-thing you're trying to do. DAMMIT, this brings another principle to mind, "Thou shall not run unknown mystical looking commands or scripts you don't understand on thy nixy goodness, otherwise you ARE stupid and deserve any self-inflicted pain and suffering which results." RAmennnnnnn. Plenty of great resources online, plenty of bad and/or horrible, some malicious ones too, so always keep that in mind okay ? These things are key to happy nixing.

Alright ... another post done, YAY! :P

Ps, arghhhh, more .. actually this arrangement could work very well for autodevice detect and reconfig, a nixer here was having an issue with a microphone or whatever, found + shared a fix and scripted it. Just needed an automagic way to run such on device plug, a crontab and conditionals, if statements in a bash script set to run every 2-3 secs could do this nicely. When something is plugged udev + dbus, systemd, one of the nix OS subsystems is going to predictably make some change that could be targeted in a bash script. Also such a script properly structured could be set to check a certain value and simply exit, such as would be the case if the device is configged as the user wants.

While there are other approaches certainly, think this could be a fairly good one too. NOW another post done, yep ... YAY!!! Gdammit! :)
Most powerful FREE tech-support tool on the planet * HERE. *
Deb-fan
 
Posts: 889
Joined: 2012-08-14 12:27

Re: Some good bash and bash alias tricks.

Postby Deb-fan » 2020-09-14 14:53

Ps, chapter 23, pg. 375, subsection k.) Lmfao, arghhh. :P

Still want to clarify so adding https://askubuntu.com/questions/800/how ... -5-seconds , this baby and https://twpower.github.io/212-systemd-timer-example-en yep a systemd timer is better, never heard of mcron considering the sheer momentum behind systemd's development and integration using one of its features should always be a first thought, it was for me anyway, that being use of a timer unit.

Also of course still other means to this end, event triggered responses, like running scripts or reconfig cmds on a targeted device when plugged. Hacking cron would be dirty and nasty with much better and cleaner options avail. Fact time has come to determine why-the-hades i should even keep cron around ? Extraneous services are a bigtime no, no. :) Hadnt occurred it can't handle computing tasks in secs w/o ugly hackery ... WTH, WHY? That's ridiculous in the context of something like computing.
Most powerful FREE tech-support tool on the planet * HERE. *
Deb-fan
 
Posts: 889
Joined: 2012-08-14 12:27

Re: Some good bash and bash alias tricks.

Postby Deb-fan » 2020-09-22 13:00

Okay and now cometh more bash dorking. :D

A recent thread about setting a default power governor got me messing around with this approach. Figured it out to my satisfaction and sharing the results. In the following, I'm switching the governor in use w/o password, just another crappy bash script created in /usr/local/bin named mine pgov.sh You need to chmod the thing to make executable as shown through-out this thread and need to add it to whatever file or make a new one if you don't have one as described above also in /etc/sudoers.d so that any privileged commands can be run by your user w/o entering passwd. Anyway at this point I've got an executable file /usr/local/bin/pgov.sh here's the contents.

Code: Select all
#!/bin/bash

   query=$(cat /sys/devices/system/cpu/cpufreq/policy0/scaling_governor)

if [ "$query" == "ondemand" ]; then

   echo performance > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor && echo performance > /sys/devices/system/cpu/cpufreq/policy1/scaling_governor

else

   echo ondemand > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor &&  echo ondemand > /sys/devices/system/cpu/cpufreq/policy1/scaling_governor

echo 30 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold

echo 4 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor

echo  250000 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate

fi

exit 0


In my case I'm checking a file with a query, if that files content is "ondemand" it runs the next stuff, setting the performance power governor on both of my dual-core's processor cores. Clearly if you have more cores, prefer other governors etc, adapt this junk to reflect that. Which that governor (performance)will run w cores at max-freq until I re-run or trigger this script. That can be done via bash alias, keybind, panel launcher, desktop icon, menu entry etc. Simply by using "sudo /usr/local/bin/pgov.sh" in them to run the script. When I want to switch back to the ondemand governor, that's what I'd do, run it again via whichever means, the script notes that files value is NOT set to "ondemand" thus runs the cmds after the else in the script, that sets ondemand back as the governor being used.

NOTE: That string of cmds after the ondemand governor has been set are tweaks/preferences which I'm applying to adjust the ondemand's up_threshold, sampling_down_factor and sampling_rate, you may want other things in which case, yep ... obvioulsy remove those lines from this script. The interesting thing I noted and why I had to add those lines, I was adjusting those settings via a script that gets run at system startup. However when doing the above, switching to performance and back to ondemand, noticed all the defaults normally used with the ondemand governor get restored and those defaults suck, so did that to reset them to my preferences.

Whatever you set these to needs to be one of the scaling governors available on your system of course, easy to find out which those are, ask google how ... End result, this gives a great example of how you'd set such a thing up on your system and what doing so let's me do, switch between power governor's on-the-fly w/o bothering with stuff like cpupower or entering a password, blahblah. That's a wrap on this nonsense. :D
Most powerful FREE tech-support tool on the planet * HERE. *
Deb-fan
 
Posts: 889
Joined: 2012-08-14 12:27


Return to Docs, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 3 guests

fashionable