Archive for the ‘bash’ Category
Fedora Install LAMP
My students wanted an extra credit assignment, so I thought a LAMP configuration and test would be appropriate. The only problem was I hadn’t added it to their course VMware instance. So, here are the instructions to install Apache2, PHP, and MySQLi for a complete LAMP stack when MySQL is already installed.
The post builds on my Fedora Install of MySQL and MySQL Workbench on Fedora posts from last year. It also presumes that you’ve installed a studentdb
database but you need to know how to do that let me know (but it hasn’t changed much from the example at the bottom of this old MySQL 5.1 blog post).
You install Apache2 with the following command as the root
user, or with the sudo
command as a sudoer
-list user:
yum install httpd |
The following displays the results of starting the yum
utility to install httpd
, and you need to reply with a y
to complete the installation:
Loaded plugins: langpacks, refresh-packagekit mysql-connectors-community | 2.5 kB 00:00 mysql-tools-community | 2.5 kB 00:00 mysql56-community | 2.5 kB 00:00 pgdg93 | 3.6 kB 00:00 updates/20/x86_64/metalink | 16 kB 00:00 updates | 4.9 kB 00:00 updates/20/x86_64/primary_db | 13 MB 00:04 (1/2): updates/20/x86_64/updateinfo | 1.9 MB 00:02 (2/2): updates/20/x86_64/pkgtags | 1.4 MB 00:01 Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.4.10-2.fc20 will be installed --> Processing Dependency: httpd-tools = 2.4.10-2.fc20 for package: httpd-2.4.10-2.fc20.x86_64 --> Processing Dependency: system-logos-httpd for package: httpd-2.4.10-2.fc20.x86_64 --> Running transaction check ---> Package fedora-logos-httpd.noarch 0:21.0.1-1.fc20 will be installed ---> Package httpd-tools.x86_64 0:2.4.10-2.fc20 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: httpd x86_64 2.4.10-2.fc20 updates 1.2 M Installing for dependencies: fedora-logos-httpd noarch 21.0.1-1.fc20 fedora 28 k httpd-tools x86_64 2.4.10-2.fc20 updates 79 k Transaction Summary ================================================================================ Install 1 Package (+2 Dependent packages) Total download size: 1.3 M Installed size: 4.0 M Is this ok [y/d/N]: y Downloading packages: (1/3): fedora-logos-httpd-21.0.1-1.fc20.noarch.rpm | 28 kB 00:00 (2/3): httpd-2.4.10-2.fc20.x86_64.rpm | 1.2 MB 00:01 (3/3): httpd-tools-2.4.10-2.fc20.x86_64.rpm | 79 kB 00:00 -------------------------------------------------------------------------------- Total 815 kB/s | 1.3 MB 00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction (shutdown inhibited) Installing : httpd-tools-2.4.10-2.fc20.x86_64 1/3 Installing : fedora-logos-httpd-21.0.1-1.fc20.noarch 2/3 Installing : httpd-2.4.10-2.fc20.x86_64 3/3 Verifying : httpd-2.4.10-2.fc20.x86_64 1/3 Verifying : fedora-logos-httpd-21.0.1-1.fc20.noarch 2/3 Verifying : httpd-tools-2.4.10-2.fc20.x86_64 3/3 Installed: httpd.x86_64 0:2.4.10-2.fc20 Dependency Installed: fedora-logos-httpd.noarch 0:21.0.1-1.fc20 httpd-tools.x86_64 0:2.4.10-2.fc20 Complete! |
Next, you install php
as the root
user with the following command:
yum install php |
The following displays when you install php
, and you need to reply with a y
to complete the installation:
Loaded plugins: langpacks, refresh-packagekit Resolving Dependencies --> Running transaction check ---> Package php.x86_64 0:5.5.22-1.fc20 will be installed --> Processing Dependency: php-common(x86-64) = 5.5.22-1.fc20 for package: php-5.5.22-1.fc20.x86_64 --> Processing Dependency: php-cli(x86-64) = 5.5.22-1.fc20 for package: php-5.5.22-1.fc20.x86_64 --> Running transaction check ---> Package php-cli.x86_64 0:5.5.22-1.fc20 will be installed ---> Package php-common.x86_64 0:5.5.22-1.fc20 will be installed --> Processing Dependency: php-pecl-jsonc(x86-64) for package: php-common-5.5.22-1.fc20.x86_64 --> Running transaction check ---> Package php-pecl-jsonc.x86_64 0:1.3.6-1.fc20 will be installed --> Processing Dependency: /usr/bin/pecl for package: php-pecl-jsonc-1.3.6-1.fc20.x86_64 --> Processing Dependency: /usr/bin/pecl for package: php-pecl-jsonc-1.3.6-1.fc20.x86_64 --> Running transaction check ---> Package php-pear.noarch 1:1.9.5-6.fc20 will be installed --> Processing Dependency: php-xml for package: 1:php-pear-1.9.5-6.fc20.noarch --> Processing Dependency: php-posix for package: 1:php-pear-1.9.5-6.fc20.noarch --> Running transaction check ---> Package php-process.x86_64 0:5.5.22-1.fc20 will be installed ---> Package php-xml.x86_64 0:5.5.22-1.fc20 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: php x86_64 5.5.22-1.fc20 updates 2.6 M Installing for dependencies: php-cli x86_64 5.5.22-1.fc20 updates 3.9 M php-common x86_64 5.5.22-1.fc20 updates 1.0 M php-pear noarch 1:1.9.5-6.fc20 updates 343 k php-pecl-jsonc x86_64 1.3.6-1.fc20 updates 34 k php-process x86_64 5.5.22-1.fc20 updates 77 k php-xml x86_64 5.5.22-1.fc20 updates 247 k Transaction Summary ================================================================================ Install 1 Package (+6 Dependent packages) Total download size: 8.2 M Installed size: 32 M Is this ok [y/d/N]: y Downloading packages: (1/7): php-5.5.22-1.fc20.x86_64.rpm | 2.6 MB 00:03 (2/7): php-cli-5.5.22-1.fc20.x86_64.rpm | 3.9 MB 00:03 (3/7): php-common-5.5.22-1.fc20.x86_64.rpm | 1.0 MB 00:00 (4/7): php-pear-1.9.5-6.fc20.noarch.rpm | 343 kB 00:00 (5/7): php-pecl-jsonc-1.3.6-1.fc20.x86_64.rpm | 34 kB 00:00 (6/7): php-process-5.5.22-1.fc20.x86_64.rpm | 77 kB 00:00 (7/7): php-xml-5.5.22-1.fc20.x86_64.rpm | 247 kB 00:00 -------------------------------------------------------------------------------- Total 1.1 MB/s | 8.2 MB 00:07 Running transaction check Running transaction test Transaction test succeeded Running transaction (shutdown inhibited) Installing : php-cli-5.5.22-1.fc20.x86_64 1/7 Installing : php-process-5.5.22-1.fc20.x86_64 2/7 Installing : php-xml-5.5.22-1.fc20.x86_64 3/7 Installing : 1:php-pear-1.9.5-6.fc20.noarch 4/7 Installing : php-common-5.5.22-1.fc20.x86_64 5/7 Installing : php-pecl-jsonc-1.3.6-1.fc20.x86_64 6/7 Installing : php-5.5.22-1.fc20.x86_64 7/7 Verifying : php-5.5.22-1.fc20.x86_64 1/7 Verifying : php-common-5.5.22-1.fc20.x86_64 2/7 Verifying : php-cli-5.5.22-1.fc20.x86_64 3/7 Verifying : 1:php-pear-1.9.5-6.fc20.noarch 4/7 Verifying : php-process-5.5.22-1.fc20.x86_64 5/7 Verifying : php-xml-5.5.22-1.fc20.x86_64 6/7 Verifying : php-pecl-jsonc-1.3.6-1.fc20.x86_64 7/7 Installed: php.x86_64 0:5.5.22-1.fc20 Dependency Installed: php-cli.x86_64 0:5.5.22-1.fc20 php-common.x86_64 0:5.5.22-1.fc20 php-pear.noarch 1:1.9.5-6.fc20 php-pecl-jsonc.x86_64 0:1.3.6-1.fc20 php-process.x86_64 0:5.5.22-1.fc20 php-xml.x86_64 0:5.5.22-1.fc20 Complete! |
After installing the software, you can set the Apache server to start automatically with the following command:
chkconfig httpd on |
However, that command only starts the Apache server the next time you boot the server. You use the following command as the root
user to start the Apache server:
apachectl start |
You can verify the installation with the following command as the root
user:
ps -ef | grep httpd | grep -v grep |
It should return:
root 5433 1 0 17:03 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 5434 5433 0 17:03 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 5435 5433 0 17:03 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 5436 5433 0 17:03 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 5437 5433 0 17:03 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 5438 5433 0 17:03 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 5442 5433 0 17:03 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND |
and, then verify the listening port with the following command as the root
user:
netstat -tulpn | grep :80 |
It should return the following when both the Apache server is listening on port 80 and the Oracle multi-protocol server is listening on port 8080:
tcp6 0 0 :::80 :::* LISTEN 5433/httpd tcp6 0 0 :::8080 :::* LISTEN 1505/tnslsnr |
After verifying the connection, you can test it by creating the traditional info.php
program file in the /var/www/http
directory. The file should contain the following:
1 2 3 | <?php phpinfo(); ?> |
You can test it by opening the Firefox browser and entering the following URL from the Fedora Linux image:
http://localhost/info.php |
It should display the typical diagnostic page. This verifies the configuration of the Apache and PHP servers. The next step verifies whether you have the mysqli
library to connect to the MySQL database.
You create a mysqli_check.php
script, like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <html> <header> <title>Static Query Object Sample</title> <style type="text/css"> /* HTML element styles. */ table {background:white;border-style:solid;border-width:3px;border-color:black;border-collapse:collapse;} th {text-align:center;font-style:bold;background:lightgray;border:solid 1px gray;} td {border:solid 1px gray;} /* Class tag element styles. */ .ID {min-width:50px;text-align:right;} .Label {min-width:200px;text-align:left;} </style> </header> <body> <?php if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) { print 'mysqli not installed.'; } else { print 'mysqli installed.'; } ?> </script> </body> </html> |
You can test it with the following URL from the local browser:
http://localhost/mysqli_check.php |
If it’s installed you can skip the next step, but if not you need to run yum
in expert mode as follows (the check for php-mysql
isn’t really necessary because it’s too old a version but good practice):
[root@localhost etc]# yum shell Loaded plugins: langpacks, refresh-packagekit > remove php-mysql No Match for argument: php-mysql > install php-mysqlnd > run --> Running transaction check ---> Package php-mysqlnd.x86_64 0:5.5.22-1.fc20 will be installed --> Processing Dependency: php-pdo(x86-64) = 5.5.22-1.fc20 for package: php-mysqlnd-5.5.22-1.fc20.x86_64 --> Running transaction check ---> Package php-pdo.x86_64 0:5.5.22-1.fc20 will be installed --> Finished Dependency Resolution ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: php-mysqlnd x86_64 5.5.22-1.fc20 updates 293 k Installing for dependencies: php-pdo x86_64 5.5.22-1.fc20 updates 141 k Transaction Summary ================================================================================ Install 1 Package (+1 Dependent package) Total download size: 433 k Installed size: 1.4 M Is this ok [y/d/N]: y Downloading packages: (1/2): php-mysqlnd-5.5.22-1.fc20.x86_64.rpm | 293 kB 00:00 (2/2): php-pdo-5.5.22-1.fc20.x86_64.rpm | 141 kB 00:00 -------------------------------------------------------------------------------- Total 427 kB/s | 433 kB 00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction (shutdown inhibited) Installing : php-pdo-5.5.22-1.fc20.x86_64 1/2 Installing : php-mysqlnd-5.5.22-1.fc20.x86_64 2/2 Verifying : php-pdo-5.5.22-1.fc20.x86_64 1/2 Verifying : php-mysqlnd-5.5.22-1.fc20.x86_64 2/2 Installed: php-mysqlnd.x86_64 0:5.5.22-1.fc20 Dependency Installed: php-pdo.x86_64 0:5.5.22-1.fc20 Finished Transaction > quit |
You should note that this also installed PDO. One caveat, before you rerun the mysqli_check.php
script from a browser, you need to restart the Apache server. You can do that as the root
user with the following syntax:
apachectl restart |
You can retest it with the following URL from the local browser:
http://localhost/mysqli_check.php |
At this point you should have everything installed to test your connection the MySQL database. As mentioned, this example extends my instructions for installing MySQL on the Fedora instance.
The following query.php
file tests your ability to connect to the MySQL database with the mysqli driver, and it uses the studentdb and video store example from my Oracle Database 11g and MySQL 5.6 Developer Handbook:
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | <html> <header> <title>Static Query Object Sample</title> <style type="text/css"> /* HTML element styles. */ table {background:white;border-style:solid;border-width:3px;border-color:black;border-collapse:collapse;} th {text-align:center;font-style:bold;background:lightgray;border:solid 1px gray;} td {border:solid 1px gray;} /* Class tag element styles. */ .ID {min-width:50px;text-align:right;} .Label {min-width:200px;text-align:left;} </style> </header> <body> <?php // Assign credentials to connection. $mysqli = new mysqli("localhost", "student", "student", "studentdb"); // Check for connection error and print message. if ($mysqli->connect_errno) { print $mysqli->connect_error."<br />"; print "Connection not established ...<br />"; } else { // Declare a static query. $query = "SELECT au.system_user_id, au.system_user_name FROM system_user au" ; // Loop through a result set until completed. do { // Attempt query and exit with failure before processing. if (!$stmt = $mysqli->query($query)) { // Print failure to resolve query message. print $mysqli->error."<br />"; print "Failed to resolve query ...<br />"; } else { // Print the opening HTML table tag. print '<table><tr><th class="ID">ID</th><th class="Label">User Role Name</th></tr>'; // Fetch a row for processing. while( $row = $stmt->fetch_row() ) { // Print the opening HTML row tag. print "<tr>"; // Loop through the row's columns. for ($i = 0;$i < $mysqli->field_count;$i++) { // Handle column one differently. if ($i == 0) print '<td class="ID">'.$row[$i]."</td>"; else print '<td class="Label">'.$row[$i]."</td>"; } // Print the closing HTML row tag. print "</tr>"; } } } while( $mysqli->next_result()); // Print the closing HTML table tag. print "</table>"; // Release connection resource. $mysqli->close(); } ?> </script> </body> </html> |
This should display the following in the browser:
You can see how to open port 80 for the Apache server in this blog post. If you want to work with blob data types, you’ll also need to use yum
to install the php-gd
library. You can read my LAMP php-gd
library blog post to learn how to install the libraries. As always, I hope a step-by-step approach without assumptions helps those learning MySQL.
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 |