LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Useful custom commands for Slackware (https://www.linuxquestions.org/questions/slackware-14/useful-custom-commands-for-slackware-174647/)

gnashley 06-06-2004 05:46 AM

Yeah great! i just add |cut -f2 -d '=' to that and it gets me what I want.
Does -z do like -v except it eliminates all FIELDS that don't match, or ??

thegeekster 06-06-2004 06:02 AM

-z is for testing empty strings.................in this case, the test is for NOT an empty string [ ! -z ... ], and by using the 'for' statement, it breaks up the input from the 'cat' command whenever 'for' parses any whitespace (blank spaces, tabs) or newlines, thereby letting you test each space-delimited field separately.......... :)

ivanatora 06-06-2004 07:14 AM

Re: *** chngcd ***
 
Quote:

Originally posted by thegeekster
Code:

cat << "__EOF__" > /usr/local/bin/chngcd && chmod 755 /usr/local/bin/chngcd
#!/bin/sh
#*******************************************************************************
# Name: chngcd

# Mount point for CDROM device
CDROM=/mnt/cdrom

umount -l $CDROM 2> /dev/null
eject $CDROM

echo -en "\n After replacing or removing the CD, simply press [Enter]..." \
  && read ans && echo
mount $CDROM 2> /dev/null
__EOF__


It doesn't work because the mount, umount and eject commands are available only for the root user. I prefer sudoing it:
/usr/local/bin/cdrom:
### beginning ###
case "$1" in
'mount')
sudo /sbin/mount /mnt/cdrom/ ;;
'umount')
sudo /sbin/umount /mnt/cdrom/ ;;
*)
echo "Usage $0 mount|umount" ;;
esac
### end ###
And following in my
/etc/sudoers
##begin##
ivanatora ALL=NOPASSWD: /sbin/mount /mnt/cdrom/,/sbin/umount /mnt/cdrom/
##end##
Of course 'ivanatora' is my username, so if you want this to work you should change this. It can be easily modified to eject the cdrom, but I can't see the point.

thegeekster 06-06-2004 07:39 AM

Re: Re: *** chngcd ***
 
Quote:

Originally posted by ivanatora
It doesn't work because the mount, umount and eject commands are available only for the root user...
Not on my machine...............those commands are in bin directories, not sbin directories................if you have problems, then it's probably a matter of how you're permissions are set for the CDROM device.............usually, the CDROM is set for anyone to mount and unmount..............otherwise CDROMs wouldn't be very useful for users.................. :)

thegeekster 06-06-2004 09:07 AM

If anyone is having problems, there are two ways to overcome it....................either add the user to the same group as the block device ("disk" for Slackware), or change the permissions on the block device to make it readable for "others", ie., brw-r--r--

If you add the user to the same group as the block device for the CDROM, you might have to logout completely or reboot the machine............... :)

usercsr 06-06-2004 11:05 AM

thanks guys, those are really useful scripts.

akshunj 06-06-2004 01:02 PM

Is there a page anywhere out there archiving all the useful bash scripts???

--Akshun J

thegeekster 06-06-2004 04:26 PM

Quote:

Originally posted by akshunj
Is there a page anywhere out there archiving all the useful bash scripts???

--Akshun J

By "out there", if you mean on the web, I started this thread a while ago with this mind:

Shell scripts on the web

:)

akshunj 06-06-2004 05:27 PM

Nice. That will get my feet wet. Teaches me to come in at the end of a thread...

--Akshun J

Neoslak 06-06-2004 06:33 PM

Here is a useful, if totally simplistic script, that is handy to see what Slackware packages in a given directory are *not* installed. For instance, I keep a local mirror of Slackware-current and I want to know if there are any packages in my slackware-current/slackware/gnome directory that are not already installed. I put a copy of this script in /usr/local/bin and change to /home/ftp/pub/slackware-current/slackware/gnome and run packcheck.sh. If anybody wants to improve on this, post your improvements here.

--------------------
#!/bin/sh

for pack in $(ls *.tgz); do
pack=$(basename $pack .tgz)
if [ ! -f /var/log/packages/$pack ]; then
echo "No Package $pack found"
fi
done
------------------

Chuck

thegeekster 06-14-2004 01:56 PM

*** whichpkg UPDATE ***
 
NOTE: This update is superseded by the changes posted here..... :)

cassiusclay 06-14-2004 05:36 PM

moving my post

Bebo 06-15-2004 12:30 PM

I just wanted to say a big THANKS to you geekster! I've been using your scripts a bit and find them very useful :)

thegeekster 07-07-2004 04:31 AM

*** FINAL UPDATES for lspkg, whichpkg, and pkginfo ***
 
Okay, I think I've gone about as far as I can with these three scripts, lspkg, whichpkg, and pkginfo................They are all converted over from using regular expression syntax to wildcard matching (globbing). While not true globbing, they are close enough for practical purposes here...........If you're interested knowing what the difference is, read the manpages for globbing and regular expressions, 'man 7 glob' and 'man 7 regexp'. (Note - For KDE users, you can view the manpages in a html format by entering these urls in Konqueror, 'man:/glob(7)' and 'man:/regexp(7)'. This only works in Konqueror, not any other browser in KDE.).......Be sure to include the number 7 in both............

I did a major overhaul for the whichpkg script, making it easier to read the output, filtering out more of the unwanted garbage, and allowing for multiple search terms. It ended up being a bit of a challenge, more than I had anticipated....... :)..........but I think I've got it right (it sure did sharpen my regexp skills.......LOL).............A few search terms were quite unpredictable, most notably the searches for "ln", "file", "install" and "sh"...........If there are others you come across which seem not quite right, be sure to post them here and I'll fix it. otherwise this is pretty much the final update.

The other two were mostly to convert to using wildcard searching (pkginfo) or a minor change in the usage of the wildcards in the search term (lspkg)..........Again, I don't see where they can go much farther, so these will also be the final updates.

HOWEVER................I'm going to create another Slackware specific script to deal with orphaned files by looking at all the system files and matching them against the list of files found in the /var/log/packages/ and /var/log/scripts/ directories..............Then you will be presented with a report of all the files that aren't accounted for from the installed packages..............Some of these may be from various scripts and files you may have added manually, such as these scripts, but some may be leftovers from old installations no longer around.................Either way, you will have a list to look over and decide for yourself whether they belong there or not..............The reason for this script is from some of the posts I've seen recently asking about what files are safe to remove, or a way to determine which files are not wanted or needed...........I do love a challenge............. :D

Okay, enought talk, the changes have already been made in the top post (post #1) above....



EDIT: Changed line number 53 in "pkginfo" script by removing the path "/var/log/packages/" (The third line from the end, above the two "esac" lines). Thanks goes to carboncopy for pointing out this error. :)

EDIT2: More changes needed in the "pkginfo" script as noted below.

carboncopy 07-07-2004 04:53 AM

Hi! I tested out all three new one but pkginfo seems to be not working properly for me. This is what happens:

Code:

bash-2.05b# ./pkginfo gnome

-------------------------------------------------------------------------------
 More than one package was found matching the name, "gnome".
 Choose a package from the following list (Hint: Use the mouse to copy-n-paste
 the desired package name)...
-------------------------------------------------------------------------------

/var/log/packages/gnome-applets-2.6.1-i486-1
/var/log/packages/gnome-audio-2.0.0-noarch-1
/var/log/packages/gnome-desktop-2.6.2-i486-1
/var/log/packages/gnome-games-2.6.1-i486-3
/var/log/packages/gnome-icon-theme-1.2.3-noarch-1
/var/log/packages/gnome-keyring-0.2.1-i486-1
/var/log/packages/gnome-media-2.6.2-i486-1
/var/log/packages/gnome-mime-data-2.4.1-noarch-1
/var/log/packages/gnome-netstatus-2.6.1-i486-1
/var/log/packages/gnome-panel-2.6.2-i486-1
/var/log/packages/gnome-session-2.6.2-i486-1
/var/log/packages/gnome-speech-0.3.3-i486-1
/var/log/packages/gnome-system-monitor-2.6.0-i486-1
/var/log/packages/gnome-terminal-2.6.1-i486-1
/var/log/packages/gnome-themes-2.6.2-i486-1
/var/log/packages/gnome-themes-extras-0.7-i486-1
/var/log/packages/gnome-utils-2.6.2-i486-1
/var/log/packages/gnome-vfs-2.6.1.1-i486-2
/var/log/packages/libgail-gnome-1.0.4-i486-1

-------------------------------------------------------------------------------
 Enter package name here: gnome-audio
cat: /var/log/packages//var/log/packages/gnome-audio-2.0.0-noarch-1: No such file or directory



All times are GMT -5. The time now is 06:48 AM.