Archive for the ‘bash’ Category
Wrapping SQL*Plus
One annoying thing from installing Oracle Database 11g on Fedora, was that the up arrows for command history didn’t work. I decided to fix that today after seeing Lutz Hartmann’s article on rlwrap
. Unfortunately, the epel
(Extra Packages for Enterprise Linux) package he recommended doesn’t run on Fedora 20. You can read my tale of woe, or skip to the .bashrc
function that fixed it when I installed only rlwrap
.
Attempting it on yum
, gave me these errors:
# yum install http://www.mirrorservice.org/sites/dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm Loaded plugins: langpacks, refresh-packagekit epel-release-6-8.noarch.rpm | 14 kB 00:00 Examining /var/tmp/yum-root-5CLTPa/epel-release-6-8.noarch.rpm: epel-release-6-8.noarch Marking /var/tmp/yum-root-5CLTPa/epel-release-6-8.noarch.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package epel-release.noarch 0:6-8 will be installed --> Processing Conflict: epel-release-6-8.noarch conflicts fedora-release No package matched to upgrade: epel-release --> Finished Dependency Resolution Error: epel-release conflicts with fedora-release-20-3.noarch You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles –nodigest |
Poking around for an epel
fix wasn’t successful, so I chose to install only the rlwrap
package. Here’s that command and log file:
[root@localhost ~]# yum install rlwrap Loaded plugins: langpacks, protectbase, refresh-packagekit 0 packages excluded due to repository protections Resolving Dependencies --> Running transaction check ---> Package rlwrap.x86_64 0:0.41-1.fc20 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: rlwrap x86_64 0.41-1.fc20 updates 95 k Transaction Summary ================================================================================ Install 1 Package Total download size: 95 k Installed size: 204 k Is this ok [y/d/N]: y Downloading packages: rlwrap-0.41-1.fc20.x86_64.rpm | 95 kB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction (shutdown inhibited) Installing : rlwrap-0.41-1.fc20.x86_64 1/1 Verifying : rlwrap-0.41-1.fc20.x86_64 1/1 Installed: rlwrap.x86_64 0:0.41-1.fc20 Complete! |
The next step was getting it to work. A sqlplus
function wrapper inside the .bashrc
file seemed the easiest. Here’s the code to the .bashrc
file:
# .bashrc # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi # Uncomment the following line if you don't like systemctl's auto-paging feature: # export SYSTEMD_PAGER= # User specific aliases and functions . /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh # Wrap sqlplus with rlwrap to edit prior lines. sqlplus() { if [ "$RLWRAP" = "0" ]; then sqlplus "$@" else rlwrap sqlplus "$@" fi } # Set vi as a command line editor. set -o vi |
As always, I hope this helps some folks.
Fixing my.cnf on Fedora
Working with a Fedora 16 VM for my students (next term) and found that the MySQL Server’s my.cnf
file worked with a Linux socket as opposed to a listener port, and that several configuration options where missing from the file. Here’s the default /etc/my.cnf
file after the package installation from the Red Hat site:
[mysqld] # Settings user and group are ignored when systemd is used. # If you need to run mysqld under different user or group, # customize your systemd unit file for mysqld according to the # instructions in http://fedoraproject.org/wiki/Systemd datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid |
Without rebuilding the log files, this seemed like the cleanest replacement for the MySQL Server my.cnf
for a development instance running on Fedora 16. If you’ve other suggestions, please let me know.
[mysqld] # Settings user and group are ignored when systemd is used. # If you need to run mysqld under different user or group, # customize your systemd unit file for mysqld according to the # instructions in http://fedoraproject.org/wiki/Systemd # Default directory. datadir=/var/lib/mysql # The TCP/IP Port the MySQL Server listens on. # ------------------------------------------------------------ # Find the machine's IP address with this command run as # the root user and use the port number specified in the # my.cnf file: # [root@localhost ~]# netstat -an | grep 3306 # ------------------------------------------------------------ bind-address=nnn.nnn.nnn.nnn port=3306 # The Linux Socket the MySQL Server uses when not using a listener. # socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # The default storage engine that will be used when creating new tables. default-storage-engine=INNODB # Set the SQL mode to strict. sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" # Set the maximum number of connections. max_connections=100 # Set the number of open tables for all threads. table_cache=256 # Set the maximum size for internal (in-memory) temporary tables. tmp_table_size=26M # Set how many threads should be kept in a cache for reuse. thread_cache_size=8 # MyISAM configuration. myisam_max_sort_file_size=100G myisam_sort_buffer_size=52M key_buffer_size=36M read_rnd_buffer_size=256K sort_buffer_size=256K # InnoDB configuration. innodb_data_home_dir=/var/lib/mysql innodb_additional_mem_pool_size=2M innodb_flush_log_at_trx_commit=1 innodb_log_buffer_size=1M innodb_buffer_pool_size=25M innodb_log_file_size=5M innodb_thread_concurrency=8 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid |
As always, I hope this helps somebody.
Handling Bash Parameters
Bash shell or shells in general hang on details. An ex-student was trying to sort something out in Learning the bash Shell, 3rd Edition, which isn’t on my short list of good shell scripting books. I concur more or less with the comment on Amazon.com that there are too few examples in the book. I think the free examples here may serve folks in lieu of a book.
Anyway, the student’s problem involved processing multiple word parameters in an array. They were confused about how to handle ${*}
, ${@}
"${*}"
and "${@}"
when assigning them into an array for subsequent processing. By the way, I did find a decent explanation of the concept on Page 89 in my copy of the book. Though my copy is a 2nd Edition.
Here’s a dressed up sample of what they were attempting to do:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #!/bin/bash # Print header information. echo "Begin Program!" echo "" # Count the call parameters. echo "Count call parameters [" ${#} "]" echo "" # Declare an array of delimited parameters. ARRAY=(${@}) # Declare a numeric constant of array elements. ELEMENTS=${#ARRAY[@]} # Does the parameter account agree with array elements. if [[ ${#} = ${#ARRAY[@]} ]]; then echo "Parameters match exploded array elements." else echo "Parameters ["${#}"] don't match exploded array elements ["${ELEMENTS}"]." fi # Echo line break. echo "" # Echo the parameter list. for (( i = 0; i < ${ELEMENTS}; i++ )); do echo " ARRAY["${i}"]=["${ARRAY[${i}]}"]" done # Print footer information. echo "" echo "End Program!" |
With the ARRAY=(${@})
assignment on line #12, they exploded the elements into individual words. They thought that the IFS
(Internal Field Separator) environment variable was defined wrong but it wasn’t.
They called the program like this from the command-line:
sample.sh "Me too" "You too" |
Then, they got this syntax and were surprised.
Begin Program! Count call parameters [ 2 ] Parameters [2] don't match exploded array elements [4]. ARRAY[0]=[Me] ARRAY[1]=[too] ARRAY[2]=[You] ARRAY[3]=[too] End Program! |
They were close. The ARRAY=(${@})
assignment on line #12. There attempt to fix it with ARRAY=(${*})
led nowhere because it’s more or less the same and explodes into 4 words. To their credit, they put quotes around it like this ARRAY=("${*}")
and got two parameters but one array element, as shown below:
Begin Program! Count call parameters [ 2 ] Parameters [2] don't match exploded array elements [1]. ARRAY[0]=[Me too You too] End Program! |
What they needed was ARRAY=("${@}")
on line #12 to explode quote delimited parameters. Here’s a complete working example of the final code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #!/bin/bash # Print header information. echo "Begin Program!" echo "" # Count the call parameters. echo "Count call parameters [" ${#} "]" echo "" # Declare an array of delimited parameters. ARRAY=("${@}") # Declare a numeric constant of array elements. ELEMENTS=${#ARRAY[@]} # Does the parameter account agree with array elements. if [[ ${#} = ${#ARRAY[@]} ]]; then echo "Parameters match exploded array elements." else echo "Parameters ["${#}"] don't match exploded array elements ["${ELEMENTS}"]." fi # Echo line break. echo "" # Echo the parameter list. for (( i = 0; i < ${ELEMENTS}; i++ )); do echo " ARRAY["${i}"]=["${ARRAY[${i}]}"]" done # Print footer information. echo "" echo "End Program!" |
Changing that one element yields their desired output:
Begin Program! Count call parameters [ 2 ] Parameters match exploded array elements. ARRAY[0]=[Me too] ARRAY[1]=[You too] End Program! |
As always, I hope this helps some folks.
VMWare Fusion Permissions
It’s always interesting when I have to sort out problems with VMWare Fusion on my Mac OS X. Right, as you guessed, interesting means frustrating. 😉 What started the whole thing was my investigating why VMWare networking would sometimes not start. I noticed the problem began after my upgrade to VMWare Fusion 3.1.0 (261058).
Rather than reboot the Mac OS X, which has fixed the problem, I tried to restart the service after closing my VMs. You can find how to do that in this older post of mine.
When I tried to restart it with the following command:
# sudo /Library/Application\ Support/VMware\ Fusion/boot.sh --restart |
I got the following error on VMWare file permissions:
VMware Fusion 261058: Shutting down VMware Fusion: Stopped DHCP service on vmnet1 Disabled hostonly virtual adapter on vmnet1 Stopped DHCP service on vmnet8 Stopped NAT service on vmnet8 Disabled hostonly virtual adapter on vmnet8 Stopped all configured services on all networks No matching processes were found No matching processes were found No matching processes were found No matching processes were found No matching processes were found No matching processes were found (kernel) Kext com.vmware.kext.vmcrosstalk not found for unload request. Failed to unload com.vmware.kext.vmcrosstalk - (libkern/kext) not found. (kernel) Kext com.vmware.kext.vmmon not found for unload request. Failed to unload com.vmware.kext.vmmon - (libkern/kext) not found. VMware Fusion 261058: Starting VMware Fusion: 2010-06-10 22:22:30.588 repair_packages[455:607] PackageKit: *** Missing bundle identifier: /Library/Receipts/vpn.pkg Verifying files from package 'com.vmware.fusion.application' on '/'. Permissions differ on "Library/Application Support/VMware Fusion/VMDKMounter.app/Contents/MacOS/vmware-vmdkMounter", should be -rwxr-xr-x , they are -rwsr-xr-x . Warning: SUID file 'Library/Application Support/VMware Fusion/VMDKMounter.app/Contents/MacOS/vmware-vmdkMounter' has been modified and will not be repaired. Finished verifying files from package 'com.vmware.fusion.application' on '/'. Started network services Verifying and re-installing files from /Library/Application Support/VMware Fusion/thnuclnt |
Navigating to the directory, an ls -al
found the two files below and their respective permissions.
drwxr-xr-x 4 root wheel 136 Jun 10 22:51 . drwxr-xr-x 5 root wheel 170 May 27 21:22 .. -rwsr-xr-x 1 root wheel 1593620 May 21 03:51 vmware-vmdkMounter -rwsr-xr-x 1 root wheel 1475396 May 21 03:51 vmware-vmdkMounterTool |
I thought perhaps both files required the same permissions but I was wrong. If you change the permissions on the vmware-vmdkMounterTool
file, you’ll raise an error telling you that it should be -rwsr-xr-x
. If you make that same mistake too, I’ve got the reset syntax at the bottom of the post.
You should only change the file permissions of vmware-vmdkMounter
file. The following syntax lets you remove the sticky bit from the user permissions but you’ll need the root password (the administrator password).
sudo chmod u=rwx,go=rx vmware-vmdkMounter |
That should leave you with the following permissions:
drwxr-xr-x 4 root wheel 136 Jun 10 22:51 . drwxr-xr-x 5 root wheel 170 May 27 21:22 .. -rwxr-xr-x 1 root wheel 1593620 May 21 03:51 vmware-vmdkMounter -rwsr-xr-x 1 root wheel 1475396 May 21 03:51 vmware-vmdkMounterTool |
When you restart you should get the following pseudo clean output. Pseudo because apparently the two errors are not meaningful. At least, I couldn’t find anything on them and VMWare Fusion now works. I’ll probably investigate this a bit more later, and I’ll update anything in this post. If you know something, post it as a comment to help everybody.
VMware Fusion 261058: Shutting down VMware Fusion: Stopped DHCP service on vmnet1 Disabled hostonly virtual adapter on vmnet1 Stopped DHCP service on vmnet8 Stopped NAT service on vmnet8 Disabled hostonly virtual adapter on vmnet8 Stopped all configured services on all networks No matching processes were found No matching processes were found No matching processes were found No matching processes were found No matching processes were found No matching processes were found (kernel) Kext com.vmware.kext.vmcrosstalk not found for unload request. Failed to unload com.vmware.kext.vmcrosstalk - (libkern/kext) not found. (kernel) Kext com.vmware.kext.vmmon not found for unload request. Failed to unload com.vmware.kext.vmmon - (libkern/kext) not found. VMware Fusion 261058: Starting VMware Fusion: 2010-06-10 22:58:45.276 repair_packages[861:607] PackageKit: *** Missing bundle identifier: /Library/Receipts/vpn.pkg Verifying files from package 'com.vmware.fusion.application' on '/'. Finished verifying files from package 'com.vmware.fusion.application' on '/'. Started network services Verifying and re-installing files from /Library/Application Support/VMware Fusion/thnuclnt |
If you fat fingered the resetting command and also changed the vmware-vmdkMounterTool
file permissions, you can reset them to shared user by using the following syntax:
sudo chmod u=rwxs,go=rx vmware-vmdkMounterTool |
As always, I hope this helps others.
VMWare nabs me again …
When I run into failures on VMWare Fusion, they’re always a bit tedious. This one happened on my iMac (OS X Leopard) running VMWare 2 (both constrained to old releases by university governance policies). The VM is Microsoft Vista in an IDE partition, it hung after running too long. I had to force quit the application. On reboot the socket file was still there, and it gave the following error message when trying to start it.
Here’s the error in plain text, so search engines can find it for others.
Virtual device serial0: File "/var/folders/Sf/SfvoJITAHMq1Vp8bNI7QZU+++TM/-Tmp-//vmware-mmclaugh/thnuclnt-641/socket" exists, but no server is listening to it. There are three possible causes for this: - The server is alive but not ready yet, and you can retry later. - The server is busy communicating with another client, so you cannot run this client at the same time. - A previous server exited abruptly, and you can remove the file and try again. The device will be disconnected. |
How to fix it?
Delete the file, right? Yes, but there’s a trick. Navigating through the -Tmp-
directory required a Unix shell trick because the -
(dash) is a switch and backquoting it with a \
(backslash) didn’t work. Jeff Yoder, told me the trick to change directory into a dash leading directory name. It was this:
cd -- -Tmp- |
The --
is how most shells mark the end of options to a command. After a --
all -
(dashes) are treated as ordinary characters.
Mark Olaveson reminded me that using the present working directory before the directory name also worked. It demotes the dash to an ordinary character too.
cd ./-Tmp- |
When I got to the directory, there was the socket file. I deleted it and everything worked like a charm.
srwxrwxrwx 1 mmclaugh staff 0 Dec 8 13:04 socket |