Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Running script at user login in MATE desktop environment

26 views
Skip to first unread message

Richard Owlett

unread,
Jun 27, 2017, 4:34:32 PM6/27/17
to

I am using the MATE desktop on Debian Stretch.
I wish to run a user specific script each time a specific user logs in.
The script is known to work because I manually run it each and every
time I login.

The MATE help system lacks a usable index making finding a specific
option difficult.

One eventually arrives at
Desktop User Guide » Desktop Sessions » Setting Programs to Start
Automatically When You Log In »
which has a section titled "Startup Programs Tab" which says "You can
use the Startup Programs tab to add, modify, and remove startup programs."

The previous screen had said "The Sessions preference tool allows you to
define which programs are started automatically when you log in."

*NOWHERE* does the "help system" give Debian applicable instructions for
getting to this "Sessions preference tool". Elsewhere in the "help
system" reference is made to something similar called "System Manager".
But nothing on how to access it either.

Guidance from a MATE user would be appreciated.
TIA


Bit Twister

unread,
Jun 27, 2017, 5:21:52 PM6/27/17
to
Not a Debian or Mate user myself, but while waiting for other replies
you can click up a terminal and run "mate-control-center" where you will
have access to Startup Applications.

Richard Owlett

unread,
Jun 27, 2017, 7:42:39 PM6/27/17
to
*THANK YOU*
Not only does it work, but it demonstrates that there are at least two
distinct bugs:
1. A bug against the help system documentation - will have to
check to see if already fixed upstream.
2. A bug against Debian's implementation of the MATE desktop - there
is a warning in the help documentation about some distribution
and vendor specific implementations - will have to search the
help system for the specific reference.

Your suggestion works but triggers a warning. I will have to investigate
to see if that might be a symptom of another bug.

A followup question.
I'm relatively new to Linux, is there a thought pattern that would have
led me to your solution or was it experience speaking.

Thanks again.



Bit Twister

unread,
Jun 27, 2017, 9:41:47 PM6/27/17
to
Mostly experience. I downloaded debian mate iso and ran it live in a
VirtualBox guest just to look at the mate desktop.

Usually I use the "locate" command to find files. Since the live cd
did not have it installed, I clicked up a terminal
cd /usr/bin
ls -1 * | grep -i mate
experience suggested a settings app, so
ls -1 * | grep -i mate | grep -i set

You might want to put mate-control-center in your panel/taskbar. :)

You also might want to bookmark the following url
https://encrypted.google.com/advanced_search

extra points given if you click up a terminal and do a
man man
man bash
man grep

stepore

unread,
Jun 27, 2017, 11:50:47 PM6/27/17
to
On 06/27/2017 06:38 PM, Bit Twister wrote:
> man bash

Dear gawd. Now you've lost him for good.

Bit Twister

unread,
Jun 28, 2017, 1:57:46 AM6/28/17
to
Heheh, if he is smart, he would learn how to automate the changes he
makes for his system and user accounts.

I make an install_whatever script for apps I install, and
whatever_change script for a configuration file change.

Makes clean installs go much faster and updates less error prone.

Currently I have
ls -1 install_* | wc -l
44
install scripts and
ls -1 *_change | wc -l
99
change scripts.

For example if a new ssh comes out I run sshd_changes to fold in my
/etc/ssh/sshd_config changes.

He might also want to consider starting a file containing anything he
has to look up more than a few times and a script to search it for
keywords.

For example:
$ uh list tools disk
list_disk_info_blkid_tools_as_root lsblk -o NAME,SIZE,FSTYPE,LABEL,MOUNTPOINT,PARTLABEL,UUID | sort -V
list_disk_info_blkid_tools_as_root blkid -s device -s LABEL -s TYPE -s PARTLABEL | sort -V
list_disk_info_blkid_tools_as_root hdparm -I /dev/sda
list_disk_info_tools blkid, findfs, hdparm, lsblk


uh is a link to my ux script, which know which item to search with
whatever words are provided.

In the above example it searched my /local/doc/unix.help file.

He may also want to consider creating a "junk" account where he can play
around without dinking up his user account. That way he can
delete/create it again as many times as required.

I also have a "normal" account which I use to verify if a problem is in my
user account or if the problem is a system wide problem.

I feel it is better to have the computer work for me instead of the
computer working me. :)

For example a network check script is more preferable than me having to
to run tests manually to find a failure point. Example:

---------------------
$ network_ck
1 Testing that ping "127.0.0.1" and networking is working on wb
2 Testing that wb resolver reads /etc/hosts by "localhost"
3 Testing wb nic (enp3s0) access by ip address "192.168.11.132"
4 Testing that wb resolver reads /etc/hosts by "wb.home.test"
5 Testing that wb resolver reads /etc/hosts by "wb"
6 Testing that ISP router's ethernet "192.168.11.1" nic is alive
7 Testing that ISP modem talks coax nic "74.81.122.87"
8 Testing that ISP modem coax talks to ISP gateway "74.81.122.87.253"
9 Testing if DNS nameserver "127.0.0.1" is alive
10 Testing that ISP can route to "98.139.183.24" (yahoo.com)
11 Testing ISP can get a DNS result to "yahoo.com"
12 Testing that /etc/resolv.conf nameserver "127.0.0.1" is alive
13 Testing that /etc/resolv.conf nameserver "8.8.4.4" is alive
14 Testing that /etc/resolv.conf nameserver "8.8.8.8" is alive

Basic network connectivity is working to yahoo.com
---------------------


network_ck will dump a diagram and what test failed with where to look
and what was used in the test.

Example snippets of that code:
tps[0]="
Typical simplified FIOS hardware setup
showing possible failure points for connections, cables, or nic hardware.

.-------. .-------. .-----. .--------. .---------.
| your |(b) (e)| ISP |(f) | wall| (i)| ISP | (j)| ISP to |
| puter |-------| modem |-----| ONT |-----| gateway|-------| Internet|
'-------' | '-------' | '-----' | '--------' | or DNS |
(a) ethernet coax coax '---------'
"
tps+=("$_hm_gw_ip (e) is the ethernet ip address at the ISP modem.
$_myip_ip (f) is the coax nic ip address in the ISP modem
$_isp_gw_ip (i) is the coax ip address at the ISP gateway")

Richard Owlett

unread,
Jun 28, 2017, 3:53:00 AM6/28/17
to
I have no objections to bash although I'm not skilled with it.
I do, however, consider man pages in general to fall under the 8th
Amendment of the U. S. Constitution.
BTW I have bookmarked:
http://tldp.org/LDP/Bash-Beginners-Guide/html/
http://tldp.org/LDP/abs/html/
http://mywiki.wooledge.org/BashGuide
http://mywiki.wooledge.org/FullBashGuide


Richard Owlett

unread,
Jun 28, 2017, 3:59:16 AM6/28/17
to
On 06/28/2017 12:54 AM, Bit Twister wrote much this senior citizen
agrees with :}

Detailed response when I'm awake.

Bit Twister

unread,
Jun 28, 2017, 6:28:20 AM6/28/17
to
Yup, looking pretty much some of the same ones I have in my
/local/doc/urls file.

$ urls bash doc
http://tldp.org/LDP/Bash-Beginners-Guide/html/ ! document
http://members.iinet.net/~herman546/p20/GRUB2%20Bash%20Commands.html ! document grub2 document bootable usb
https://www.sourceware.org/autobook/autobook/autobook_119.html#Test ! bash documentation
http://cli.learncodethehardway.org/bash_cheat_sheet.pdf ! command document cmd line
http://www.freeos.com/guides/lsst/ ! bash Linux Shell Scripting Tutorial documentation
http://bahmanm.com/blogs/command-line-options-how-to-parse-in-bash-using-getopt ! document
http://spin.atomicobject.com/2011/03/30/parsing-arguments-in-bash-with-getopts/ ! document command (best)
http://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html ! document
http://cfajohnson.com/shell/?2004-05-22_shell_websites ! bash doc reference
http://www.howtoforge.com/detailed-error-handling-in-bash ! document sqlite trap
http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html ! basic shell bash doc
http://cfaj.freeshell.org/shell ! bash script tips usage doc
http://tldp.org/LDP/abs/html/index.html ! bash advanced documentation
http://mywiki.wooledge.org/BashFAQ/050 ! bash variable expansion document
http://mywiki.wooledge.org/BashGuide ! document
http://mywiki.wooledge.org/FullBashGuide ! document


I use http://tldp.org/LDP/abs/html/ to look up things I forget about.
I did cut the String Operations from
http://tldp.org/LDP/abs/html/refcards.html#AEN22828
and pasted them into my /local/doc/unix.help file to speed up any
coding needing sub-string work.

Dan Purgert

unread,
Jun 28, 2017, 6:38:47 AM6/28/17
to
Bit Twister wrote:
> [...]
> He might also want to consider starting a file containing anything he
> has to look up more than a few times and a script to search it for
> keywords.
>
> [...]
>
> uh is a link to my ux script, which know which item to search with
> whatever words are provided.

I really have to find that post I saved with your 'ux' / 'uh' script...

> [...]
> For example a network check script is more preferable than me having to
> to run tests manually to find a failure point. Example:
>
> ---------------------
> $ network_ck
> [...]

You wouldn't happen to have these tools on github or somewhere would
you?


--
|_|O|_| Registered Linux user #585947
|_|_|O| Github: https://github.com/dpurgert
|O|O|O| PGP: 05CA 9A50 3F2E 1335 4DC5 4AEE 8E11 DDF3 1279 A281

Bit Twister

unread,
Jun 28, 2017, 8:09:00 AM6/28/17
to
On Wed, 28 Jun 2017 10:35:00 -0000 (UTC), Dan Purgert wrote:
> Bit Twister wrote:
>> [...]
>> He might also want to consider starting a file containing anything he
>> has to look up more than a few times and a script to search it for
>> keywords.
>>
>> [...]
>>
>> uh is a link to my ux script, which know which item to search with
>> whatever words are provided.
>
> I really have to find that post I saved with your 'ux' / 'uh' script...

Well, it do make search man page topics much easier. :)

Should not be to find,
grep -i 'ux - search different files with user supplied keywords' /wherever/*


>
>> [...]
>> For example a network check script is more preferable than me having to
>> to run tests manually to find a failure point. Example:
>>
>> ---------------------
>> $ network_ck
>> [...]
>
> You wouldn't happen to have these tools on github or somewhere would
> you?


No, All my stuff is highly customized for my environment, coding
methodology and current Linux distribution.

My network_ck script is designed to run differently on different setups and
different ISP and tell me which cable is at fault and currently has
$ sort -u network_ck | grep -v '#' | wc -l
416
lines of code and verbage.


Like my posted ux script, here is a chopped down simplified beginners
copy you can play with.
-----8<-----8<-----8<--cut below this line----8<-----8<-----8<
#!/bin/bash
#************************************************************************
#*
#* network_ck - check each network item Release: 1.0
#*
#* Your router has a WAN ip address that you can ping.
#* You can get your internet/wan ip address with one the following:
#* wget -O- http://icanhazip.com 2>/dev/null
#* curl http://icanhazip.com/
#* curl http://myip.dnsomatic.com
#* Be sure to change 0.0.0.6 in "_wan_ip" to your WAN ip address
#*
#* You can look in your router and change _dns_isp="8.8.8.8 208.67.222.222"
#* to the router value sent by your ISP for testing.
#* Note: It can change over time.
#*
#*
#* Install:
#* save script to network_ck
#* chmod +x network_ck
#* test with command ./network_ck
#* When done:
#* cp network_ck /usr/local/bin
#*
#*
#* set _debug="debug" to see all failure messages
#*
#* Assumptions: dig is installed and script is running in Linux/Unix OS
#* If using ipv6 addresses, ping6 is installed.
#*
#*
#*
#* This is free software released to public domain. Do with it whatever you want.
#*
#*
#************************************************************************

export PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin

set -u # Show usage of unset variables as an error, to help catch typos.

_app=$(basename $0) # application name
_count=0 # temporary count variable
_ck_nic_ary=() # array of nic ip to test
_debug="" # =debug will cause all test to fail
_dns="" # temp dns ip storage
_dns_rtr="" # router dns server ip
_dns_isp="8.8.8.8 208.67.222.222" # ISP dns server
_exe=$0 # full path spec of this script
_fix_msg="" # temp fix message storage
_fix_msg_ary=() # array of fix/check instructions
_failures=0 # running failure counter
_gw_lan_ip="" # lan gateway ip address
_gw_isp_ip="" # ISP gateway ip address
_host_alias="\"$(hostname --short)\""
_host_fqdn="$(hostname --fqdn)"
_host_ip="\"$(hostname --ip-address)\""
_ip="" # temp ip variable for ping test
_ix=0 # temp index var for ck_nic and fix_msg access
_ping_cmd="" # temp ping command variable
_test_msg="" # temp test message variable
_test=0 # current test indicator
_tmp="" # temporary string variable
_tmp_fn=/var/tmp/$_app.tmp # temporary file name used for ping output
_wan_ip="0.0.0.6" # ISP gateway your router is chatting with
_yahoo_ip="98.139.183.24" # current yahoo.com ip address

set -- $(ip route)
_gw_lan_ip=$3 # set LAN gateway ip

set -- $(grep --max-count=1 nameserver /etc/resolv.conf)
_dns_rtr=$2

if [ -n "$_debug" ] ; then # set some known failure test cases
_host_alias="\"wbx tbx\""
_host_ip="\"192.168.111.135 192.168.111.100\""
fi

set -- $(IFS='.' ; echo $_wan_ip)
_gw_isp_ip=$1.$2.$3.1

##############################################################
# You can hard code value(s) here if you like
# if $(hostname whatever) is not providing normal results
# Example:
# _host_alias="just"
# _host_fqdn="just.me.here"
# _host_ip="192.168.3.3"
#
##############################################################

##############################################################
#
# This section loads what ip address is to be tested and the
# repair/troubleshooting text arrays
#
# _ck_nic_ary format is
# ip_address_to test and a brief what is being tested string
#
# _fix_msg_ary is whatever verbiage you want displayed when
# the test fails.
#
# Example test for printer:
#
# _ck_nic_ary+=("x.x.x.x printer is alive")
# _fix_msg_ary+=("Check power cord, is on, and nic led at printer")
#
##############################################################



_ck_nic_ary+=("127.0.0.1 ping and network is working on $_host_fqdn")
_fix_msg_ary+=("Problem resolution should go into /etc/hosts")

_ck_nic_ary+=("localhost resolver reads /etc/hosts ")
_fix_msg_ary+=("Problem resolution should go into /etc/hosts
Or /etc/nsswitch.conf hosts: entry needs adjustment
man nsswitch.conf
My settings: grep hosts /etc/nsswitch.conf
# hosts: mdns4_minimal files nis dns mdns4 myhostname
hosts: files dns myhostname")


#**************************************************
#* check if node's ip address has more than one value
#* If so, add a test for each one found.
#***************************************************

set -- $_host_ip
if [ $# -ne 1 ] ; then
_tmp="\\n\\tExpected only one ip address, not $_host_ip"
else
_tmp=""
fi

for _ip in $_host_ip ; do
_ck_nic_ary+=("$_ip $_host_alias nic access by ip address. $_tmp")
_fix_msg_ary+=("check led on nic socket.
use ethtool to see if it can read the hardware registers")
done
_tmp=""

_ck_nic_ary+=("$_host_fqdn resolver resolves by FQDN ")
_fix_msg_ary+=("")


#**********************************************
#* check if node's alias has more than one value
#* If so, add a test for each one found.
#**********************************************

set -- $_host_alias
if [ $# -ne 1 ] ; then
_tmp="\\n\\tExpected only one alias, not $_host_alias"
else
_tmp=""
fi

for _ip in $_host_ip ; do
_ck_nic_ary+=("$_host_alias resolver resolves by alias. $_tmp ")
_fix_msg_ary+=("Problem resolution should go into /etc/hosts
If it is on the localhost line you need to create a separate line for each
Example:
127.0.0.1 localhost.localdomain localhost
127.0.0.2 darkstar.home.test darkstar
127.0.0.3 mail.home.test mail")
done
_tmp=""

_ck_nic_ary+=("$_gw_lan_ip $_host_alias to router gateway")
_fix_msg_ary+=("Check nic led on router. reset router and $_host_alias")

_ck_nic_ary+=("$_wan_ip ISP assigned Internet ip adress")
_fix_msg_ary+=("Verify your WAN Internet ip address has not changed.
You can get your Internet/WAN ip address with one the following:
wget -O- http://icanhazip.com 2>/dev/null
curl http://icanhazip.com/
curl http://myip.dnsomatic.com
Some ISPs block pings so you need to verify you can ping the address.
If ping fails, it is blocked and you need to set _wan_ip=127.0.0.1
If works, change $_wan_ip to new value and rerun test. If still broke,
check nic leds on wire to wallplug
or coax led on the front of cable modem and reboot router.
Still broke, check all coax connections.
Still broke, it is an ISP router, coax, ONT, or ISP problem
call ISP to let them troubleshoot back to your modem")

_ck_nic_ary+=("$_gw_isp_ip ISP gateway ip adress")
_fix_msg_ary+=("Reboot ISP router. Still broke, call helpdesk")

_ck_nic_ary+=("$_dns_rtr router DNS node is alive ")
_fix_msg_ary+=("Reboot router. Still broke, call helpdesk")

_ck_nic_ary+=("$_yahoo_ip ISP can route to yahoo.com ip address ")
_fix_msg_ary+=("yahoo.com ip address may have changed or is down
ping -c1 -w1 8.8.8.8 If that works you have ISP Internet connectivity
ping -c1 -w1 yahoo.com if address is not $_yahoo_ip
change both in $_exe")

_ck_nic_ary+=("yahoo.com ISP can get a DNS result to yahoo.com")
_fix_msg_ary+=("Something wrong on the Internet
or one of the DNS servers in your connection/path is AFU")


function ping_nic ()
{
#**************************
#* test ip address via ping
#**************************

$_ping_cmd > $_tmp_fn 2>&1
if [ $? -ne 0 ] ; then
echo -e "$_test FAILURE Testing $_ip $_test_msg"
cat $_tmp_fn
echo -e "when doing a $_ping_cmd \\n"
echo -e "$_fix_msg\\n"

(( _failures++ ))
else
echo -e "$_test Passed testing $_ip $_test_msg"
fi
(( _test++ ))
} # end function ping_nic ()

function test_nic ()
{
#***********************************************************************
#* test each ip address found in the firs argument in _ck_nic_ary
#* decide if the ip is ipv4 or ipv6 and generate the required ping cmmand.
#***********************************************************************


set -- $(echo ${_ck_nic_ary[$_ix]}) # parse ck_nic_ary[$_ix]}
_ip=$1 # save first argument of string
shift # drop first argument
_test_msg=$* # save rest of string
_fix_msg=${_fix_msg_ary[$_ix]} # save repair/troubleshooting string
_ip=$(echo $_ip | tr -d '"') # strip double quotes from ip address

_count=$(echo $_ip | grep --count ':' ) # check for a :
if [ $_count -eq 0 ] ; then # its a ipv4 address
_ping_cmd="ping -c1 -w1 $_ip $_debug"
else
_ping_cmd="ping6 -c1 -w1 $_ip $_debug" # its an ipv6 ip
fi
ping_nic # run test on current ip
} # end function test_nic ()

#************************
#* main code start here
#************************


echo -e "\\n\tRunning $_exe\\n"

#*****************************************
#* check for no or multipal gateway values
#*****************************************

echo "$ route -n"
route -n
_count=$(route -n | grep --count ' UG ')
if [ $_count -ne 1 ] ; then
echo "
There is $_count gateway routes indicated in the above
where there should only be 1
"
fi

if [ "$_host_alias" = "localhost" ] ; then
echo "
Although it seems to not hurt your setup, you might consider
creating a Fully Qualified Domain (FQDN) name for your node.
Some applications will fail without one.
mysqld, postfix, sendmail, leafnode, dovecot,.. Usenet client
to name just a few. You may want to read
http://www.rfc-editor.org/rfc/rfc2606.txt
I suggest something like darkstar.home.test. Example locations:
\$ cat /etc/sysconfig/network
HOSTNAME=wb.home.test
NETWORKING=yes
CRDA_DOMAIN=US

\$ cat /etc/hostname
wb.home.test

NOTE: You will need to reboot system to make sure all apps
get notification about the new name

"
fi

echo " "

#********************
#* Now run all tests
#********************

for _ix in ${!_ck_nic_ary[*]} ; do # run all tests
let _test="$_ix + 1" # bump test counter
test_nic
done
_count=${#_ck_nic_ary[*]}

echo " "
for _dns in $_dns_isp ; do
(( _count++ ))
dig +short @$_dns yahoo.com > /dev/null 2>&1
echo -n "Test ISP DNS server $_dns "
if [ $? -ne 0 ] ; then
(( _failures++ ))
echo "FAILED
ISP DNS server $_dns fails to resolve yahoo.com.
Test used: dig +short @$_dns yahoo.com
Check your router to verify that your ISP has not given you
new/different DNS server ip addresses.
Suggest re-booting router then check its DNS ip values.
If so, update _dns_isp= in $_exe with new values.
if not call your ISP help desk.
Workaround add nameserver 8.8.8.8
to bottom of /etc/resolvconf/resolv.conf.d/head.
Next network restart or reboot will update /etc/resolv.conf
"
fi
echo "Passed"
done

rm -f $_tmp_fn

echo -e "\\nTest totoal: $_count with $_failures failures \\n"

#***************** end network_ck ******************************************

Richard Owlett

unread,
Jun 29, 2017, 7:40:41 AM6/29/17
to
On 06/27/2017 06:42 PM, Richard Owlett wrote:
[snip]
> Not only does it work, but it demonstrates that there are at least two
> distinct bugs:
> 1. A bug against the help system documentation - will have to
> check to see if already fixed upstream.
> 2. A bug against Debian's implementation of the MATE desktop - there
> is a warning in the help documentation about some distribution
> and vendor specific implementations - will have to search the
> help system for the specific reference.

Debian's implementation does *NOT* have a bug.
The problem was a combination of what _I_ expected and how _I_ read the
help text.



Dan Purgert

unread,
Jun 29, 2017, 11:29:04 AM6/29/17
to
Bit Twister wrote:
> On Wed, 28 Jun 2017 10:35:00 -0000 (UTC), Dan Purgert wrote:
>> Bit Twister wrote:
>>> [...]
>>> He might also want to consider starting a file containing anything he
>>> has to look up more than a few times and a script to search it for
>>> keywords.
>>>
>>> [...]
>>>
>>> uh is a link to my ux script, which know which item to search with
>>> whatever words are provided.
>>
>> I really have to find that post I saved with your 'ux' / 'uh' script...
>
> Well, it do make search man page topics much easier. :)
>
> Should not be to find,
> grep -i 'ux - search different files with user supplied keywords'
> /wherever/*

Yeah, but that only works when I know which backup disc it's on (long
story short - backups work, but I only copied stuff over from discs 1-4
--> /etc, /home/important (gpg keys, Documents, etc.), and fluff (News,
etc.) didn't make the cut).

Bit Twister

unread,
Jun 29, 2017, 11:40:01 AM6/29/17
to
On Thu, 29 Jun 2017 15:25:17 -0000 (UTC), Dan Purgert wrote:
> Bit Twister wrote:
>> On Wed, 28 Jun 2017 10:35:00 -0000 (UTC), Dan Purgert wrote:
>>> Bit Twister wrote:
>>
>> Should not be to find,
>> grep -i 'ux - search different files with user supplied keywords'
>> /wherever/*
>
> Yeah, but that only works when I know which backup disc it's on (long
> story short - backups work, but I only copied stuff over from discs 1-4
> --> /etc, /home/important (gpg keys, Documents, etc.), and fluff (News,
> etc.) didn't make the cut).


Tisk, tisk, I keep my scripts in a separate partition, /local/bin,
makes backups easy. I also have /local/cron and just one link in
/etc/cron* directories to run my cron stuff.

Copy of ux follows:
#! /bin/bash
#******************************************************************************
#*
#* ux - search different files with user supplied keywords. Version 2.1
#*
#* basename is called to determine command and file to use.
#*
#*
#* To add a new selection:
#* copy some_case_name stanza, set case_name, comment and
#* whatever commands needed.
#* create a link with ln -s ux new_case_name
#* or run the command ux -i
#*
#* Some linked example snippets: ls -l u*
#* ue -> ux
#* uh -> ux
#* uidx -> ux
#* ulocate -> ux
#* uman -> ux
#* urgb -> ux
#* urls -> ux
#* and to find a word in dictionary there is
#* sp -> ux
#*
#* sp usage example would be
#* sp amb d x to find ambidextrous
#*
#* Install procedure:
#* save this as ux
#* chmod +x ux
#* You install in any directory found in your $PATH variable. To check
#* echo $PATH
#* Usual location is /usr/local/bin, so
#* cp ux /usr/local/bin/ux
#* chmod +x /usr/local/bin/ux
#* cd /usr/local/bin
#* ux -i
#* cd
#*
#* NOTE: Script requires xterm to be installed.
#*
#*
#******************************************************************************

export PATH=\
/usr/local/sbin:/usr/sbin:sbin\
:/usr/local/bin:/usr/bin:/bin\
:/usr/libexec\
:/local/bin:$HOME/bin\

_cmd_line_args="$*"

which ux > /dev/null 2>&1
if [ $? -ne 0 ] ; then
which ux
echo "
ux needs to be in your path and you have followed the install procedure
"
exit 1
fi

_exe_fn=$(which ux)
_app=$(basename $0)
_node=$(hostname --short)

_tmp_fn=/$_app
_exe_dir=${_exe_fn%$_tmp_fn}
_xfont='-font 6x10 -geom 200'
_xcolor='-fg black -bg lightgrey'
_xlayout="-font 7x13 -geom 200 $_xcolor"

_tmp_fn=$HOME/tmp/$_app.x
_arg1=""
_args=""
_cmd_line=""
_tmp=""

#***************************
#* main code start here
#***************************
echo -ne '\033[?3h\033[?66h'
# echo "tput clear" >> $_tmp_fn
mkdir -p $HOME/tmp

/bin/cp /dev/null $_tmp_fn


echo "sleep 1" >> $_tmp_fn

case $_app in
ujctl)
_usage_args='bs:u:' # list of valid switches ':' indicates needs value

while getopts "$_usage_args" OPTION; do
case "$OPTION" in
b) _args="$_args -b" ;;
s) _args="$_args --since '$(date --date "$OPTARG" '+%Y-%m-%d %H:%M:%S')'" ;;
u) _args="$_args --until '$(date --date "$OPTARG" '+%Y-%m-%d %H:%M:%S')'" ;;
*)
echo "unrecognized $_app option $OPTION"
echo "$_cmd_line_args"
usage
;;
esac
done

if [ $OPTIND -gt 0 ] ; then
shift $((OPTIND-1))
set -- $*
fi
;;
ux)
set -- $_cmd_line_args
if [ $# -gt 0 ] ; then
if [ "$1" = "-i" ] ; then
cd $_exe_dir
while read -r line ; do
set -- $line
_fn=$1
if [ ! -e $_exe_dir/$_fn ] ; then
ln -sf $_exe_fn $_fn
fi
done < <(grep '#' $_exe_fn | grep ')' | tr -d '#)' | grep -v ux_fn )
echo "created:"
ls -al | grep -- '->'
exit 0
fi
fi
;;
*) ;;
esac

if [ $# -ne 0 ] ; then
_arg1=$1
shift
fi

while [ $# -ne 0 ] ; do
_tmp=$_tmp" | grep -Eie \"$1\""
shift
done


case $_app in
sp) #- search spelling dictionary (assumes words,util-linux rpms installed)
echo "look \"$_arg1\" $_tmp" >> $_tmp_fn
;;
ualias) #- search ~/.bashrc /etc/bashrc
echo "echo -e \"\n# $_exe $_cmd_line\"" >> $_tmp_fn
echo "echo -e \"looking in $HOME/.bashrc\"" >> $_tmp_fn
echo "grep -Eie \"$_arg1\" $HOME/.bashrc $_tmp" >> $_tmp_fn
echo "echo -e \"looking in /etc/bashrc\"" >> $_tmp_fn
echo "grep -Eie \"$_arg1\" /etc/bashrc $_tmp" >> $_tmp_fn
;;
udir) #- search directory for file name
echo "ls -al | grep -Eie $_arg1 $_tmp" >> $_tmp_fn
;;
udm) #- show installed display managers
echo "echo # startx selections installed:" >> $_tmp_fn
echo "ls -1 /etc/X11/dm/Sessions" >> $_tmp_fn
echo "echo ' '" >> $_tmp_fn
echo "echo System default;cat /etc/sysconfig/desktop" >> $_tmp_fn
echo "echo ' '" >> $_tmp_fn
echo "echo user desktop manger override" >> $_tmp_fn
echo "cat $HOME/.desktop $_tmp" >> $_tmp_fn
;;
uenv) #- search for environment variable
echo "env |sort | grep -Eie \"$_arg1\" $_tmp" >> $_tmp_fn
;;
uh) #- search my /local/doc/unix.help file
echo "grep -Eie \"$_arg1\" /local/doc/unix.help $_tmp" >> $_tmp_fn
;;
ujctl) #- search journalctl log
echo "echo -e \"\n# looking in journalctl $_args \"" >> $_tmp_fn
echo "journalctl $_args | grep -Eie \"$_arg1\" $_tmp" >> $_tmp_fn
;;
ukernel) #- search /usr/share/doc/kernel-doc/
arr=(
"/usr/share/doc/kernel-doc/kernel-parameters.txt"
"/usr/share/doc/kernel-doc/video4linux/bttv/Insmod-options"
"/usr/share/doc/kernel-doc/networking/ip-sysctl.txt"
"/usr/share/doc/kernel-doc/vm/slub.txt"
"/usr/share/doc/kernel-doc/clk.txt"
"/usr/share/doc/kernel-doc/cgroups/memory.txt"
"/usr/share/doc/kernel-doc/x86/x86_64/boot-options.txt"
"/usr/share/doc/kernel-doc/block/cfq-iosched.txt"
"/usr/share/doc/kernel-doc/block/cmdline-partition.txt"
"/usr/share/doc/kernel-doc/blockdev/floppy.txt"
"/usr/share/doc/kernel-doc/blockdev/paride.txt"
"/usr/share/doc/kernel-doc/blockdev/ramdisk.txt"
"/usr/share/doc/kernel-doc/cgroups/cpusets.txt"
"/usr/share/doc/kernel-doc/debugging-via-ohci1394.txt"
"/usr/share/doc/kernel-doc/fb/modedb.txt"
"/usr/share/doc/kernel-doc/filesystems/nfs/nfsroot.txt"
"/usr/share/doc/kernel-doc/ide/ide.txt"
"/usr/share/doc/kernel-doc/input/joystick.txt"
"/usr/share/doc/kernel-doc/isdn/README.HiSax"
"/usr/share/doc/kernel-doc/kdump/kdump.txt"
"/usr/share/doc/kernel-doc/laptops/sonypi.txt"
"/usr/share/doc/kernel-doc/md.txt"
"/usr/share/doc/kernel-doc/networking/ipv6.txt"
"/usr/share/doc/kernel-doc/power/video.txt"
"/usr/share/doc/kernel-doc/s390/CommonIO"
"/usr/share/doc/kernel-doc/serial-console.txt"
"/usr/share/doc/kernel-doc/sound/alsa/alsa-parameters.txt"
"/usr/share/doc/kernel-doc/sound/oss/oss-parameters.txt"
"/usr/share/doc/kernel-doc/sysctl/vm.txt"
"/usr/share/doc/kernel-doc/video4linux/meye.txt"
"/usr/share/doc/kernel-doc/vm/transhuge.txt"
"/usr/share/doc/kernel-doc/watchdog/watchdog-parameters.txt"
"/usr/share/doc/kernel-doc/x86/boot.txt"
"/usr/share/doc/kernel-doc/x86/i386/IO-APIC.txt"
"/usr/share/doc/kernel-doc/x86/intel_mpx.txt"
"/usr/share/doc/kernel-doc/dynamic-debug-howto.txt"
)
for index in ${!arr[*]} ; do
echo "echo looking in ${arr[$index]} " >> $_tmp_fn
echo "grep -Eie \"$_arg1\" ${arr[$index]} $_tmp" >> $_tmp_fn
done
;;
ulocate) #- search system's locate database
echo "locate -i -- \"$_arg1\" $_tmp" >> $_tmp_fn
;;
uls) #- search ls results
echo "ls | grep -Eie $_arg1 $_tmp" >> $_tmp_fn
;;
uman) #- search apropos
echo "apropos \"$_arg1\" $_tmp" >> $_tmp_fn
;;
umanc) #- search apropos for C functions
echo "apropos \\(3\\) | grep -i \"$_arg1\" $_tmp | egrep -v \"::|DES_|Tcl_|XC|X|TCL_|^X\" " >> $_tmp_fn
;;
ups) #- search ps aux
echo "ps aux | grep -v $_app | grep -Eie \"$_arg1\" $_tmp" >> $_tmp_fn
;;
urgb) #- search showrgb color selections (assumes rgb rpm installed)
echo "showrgb | grep -Eie \"$_arg1\" $_tmp" >> $_tmp_fn
;;
urpm) #- search for installed rpm
echo "rpm -qa \"*$_arg1*\" $_tmp" >> $_tmp_fn
;;
userv) #- search /etc/services file
echo "grep -Eie \"$_arg1\" /etc/services $_tmp" >> $_tmp_fn
;;
usysctl) #- search /etc/sysctl.d/ /run/sysctl.d/ /usr/lib/sysctl.d/*.conf
echo "echo -e \"\n# $_exe $_cmd_line\"" >> $_tmp_fn
echo "echo -e \"looking in /etc/sysctl.d/*.conf\"" >> $_tmp_fn
echo "grep -Eie \"$_arg1\" /etc/sysctl.d/*.conf $_tmp" >> $_tmp_fn
echo "echo -e \"\nlooking in /run/sysctl.d/*.conf\"" >> $_tmp_fn
echo "grep -Eie \"$_arg1\" /run/sysctl.d/*.conf $_tmp" >> $_tmp_fn
echo "echo -e \"\nlooking in /usr/lib/sysctl.d/*.conf\"" >> $_tmp_fn
echo "grep -Eie \"$_arg1\" /usr/lib/sysctl.d/*.conf $_tmp" >> $_tmp_fn
;;
xmount) #- search mount igoring fs on, cgroup, systemd lines
if [ -z "$_arg1" ] ; then
echo "mount | sort -V | grep -v cgroup | grep -v systemd| grep -v devpts | grep -v sunrpc |
grep -v named | grep -v mqueue | grep -v /fs/ | grep -v \"fs on\" " >> $_tmp_fn
else
echo "mount | sort -V | grep -v cgroup | grep -v systemd| grep -v devpts | grep -v sunrpc |
grep -v named | grep -v mqueue | grep -v /fs/ | grep -v \"fs on\" | grep $_arg1 $_tmp" >> $_tmp_fn
fi
;;
*)
echo "grep -Eie '#' $_exe_fn | grep ')' | tr -d '#)' | grep -v ux_fn | sort" >> $_tmp_fn
echo "echo \" ==cmd== - ==== brief description ============================

For any of the above to work I assume you did a
cd $(dirname $_exe)
ln -s $_app each_above_cmd_here
or you need to run $_exe_fn -i

\"
" >> $_tmp_fn
;;
esac

echo "echo \" \"" >> $_tmp_fn
echo "echo \"# Completed: $_app $_cmd_line_args\"" >> $_tmp_fn
echo "read -p \"# hit return to close $_node $_tmp_fn\" var1 " >> $_tmp_fn

echo /bin/rm $_tmp_fn >> $_tmp_fn
chmod +x $_tmp_fn
nohup xterm -title "$_node $_exe $_cmd_line_args" $_xlayout -e $_tmp_fn > /dev/null 2>&1 &

#********************* end ux ******************************

Dan Purgert

unread,
Jul 1, 2017, 11:58:27 AM7/1/17
to
Bit Twister wrote:
> On Thu, 29 Jun 2017 15:25:17 -0000 (UTC), Dan Purgert wrote:
>> Bit Twister wrote:
>>> On Wed, 28 Jun 2017 10:35:00 -0000 (UTC), Dan Purgert wrote:
>>>> Bit Twister wrote:
>>>
>>> Should not be to find,
>>> grep -i 'ux - search different files with user supplied keywords'
>>> /wherever/*
>>
>> Yeah, but that only works when I know which backup disc it's on (long
>> story short - backups work, but I only copied stuff over from discs 1-4
>> --> /etc, /home/important (gpg keys, Documents, etc.), and fluff (News,
>> etc.) didn't make the cut).
>
>
> Tisk, tisk, I keep my scripts in a separate partition, /local/bin,
> makes backups easy. I also have /local/cron and just one link in
> /etc/cron* directories to run my cron stuff.

The ones I use are. The ones that I haven't gotten around to
understanding yet, not so much.

Thanks for resending the script .
0 new messages