Posted by dmccoy | Posted in Command-Line, OS X, Ubuntu | Posted on 14-11-2011
Recently, I had an issue upgrading my Mac Pro from Ubuntu 10.10 to 11.04. After the install and the initial reboot I received a “No Bootable device found”. This isn’t the first time that this has happened to me during a Mac Pro Ubuntu upgrade. Many tech boards had offered the reset your PRAM or reset your Open Firmware as the solution to re-detecting the ubuntu partition. All had failed. Resetting your PRAM and your Open firmware won’t tell the system that “X” partition is bootable. Ultimately it came down to re-blessing the ubuntu partition with in OS X.
I used a Mac OS X startup disk to gain access to a terminal session to run the bless command.
/usr/sbin/bless --device /dev/disk2s1 --setBoot --legacy
To traverse firewalls that block incoming SSH connections or to access a computer with a non routable IP address, you can create an SSH tunnel. When creating a SSH tunnel, you’ll generate the tunnel on the host system and connect it to another system.
With the SSH command, you’ll use the “-R” flag, that allows reversible communications or a reverse tunnel.
This command that I normally use:
It states, create a reversible SSH tunnel from this localhost port 22 to USER@SERVER on port 10000.
/usr/bin/ssh -R 10000:localhost:22 USER@SERVER
You’ll need to leave this connection open otherwise the tunnel will collapse. Normally I execute a program at the other end to keep the connection alive. Some SSHd configurations will drop connections due to inactivity.
To connect to the tunnel from USER@SERVER:
use ssh to connect to your USER account on the host server via port 10000.
/usr/bin/ssh USER@localhost -p 10000
this will give you the login prompt at the host server. User your login information or you can also setup SSH Keys.
If a cron job executes with unmanaged warnings for data, you’ll generate LOTS of emails to your account. Here is an easy way to redirect all that extraneous data.
Just add “>> /dev/null 2>$1″ to the end of each of your cron jobs.
0,10,20,30,40,50 * * * * /path/to/script >> /dev/null 2>&1
I’ve been adding $argv functionality to all of my PHP maintenance scripts. I am doing this, so I don’t have to edit a variable each time I want to execute it.
A PHP $argv example.
#!/usr/bin/php
< ? PHP
# test.php
# demonstration of $argv
# Dan McCoy
# January 31 2011
$command = $argv[1];
$GLOBALS['script'] = basename($argv[0]);
$GLOBALS['ver'] = "1.0";
$GLOBALS['file'] = $argv[2];
function help() {
echo "Help for ". $GLOBALS['script'] ."\n";
echo "-h \t Help prompt \n";
echo "-v \t Version ". $GLOBALS['ver'] ."\n";
echo "-g \t Grab file from X \n";
echo "-f \t Reformat data from X \n";
echo "-l \t Load data from X \n";
}// end help
function grab(){
@exec('/opt/local/bin/wget http://webserver.com/page.php -O '. $GLOBALS['file'],$retval);
return "Grab completed ". $retval[0] ." \n";
}// end grab
function reformat() {
$fp = $GLOBALS['file'];
$file = fopen($fp,'r');
$data = fread($file,filesize($fp));
fclose($file);
$data = str_replace("<br /><br />","\n\n",$data);
$data = str_replace("<br />","\n",$data);
$data = strip_tags($data);
$data = str_replace("\t","",$data);
$fp = $GLOBALS['file'];
$file = fopen($fp,'w');
fwrite($file,$data);
fclose($file);
return "Reformating completed \n";
}// end reformat
function load() {
$fp = $GLOBALS['file'];
$file = fopen($fp,'r');
$data = fread($file,filesize($fp));
fclose($file);
return $data;
}
function delete() {
$ret = @unlink($GLOBALS['file']);
if ($ret==TRUE){
return "File has been deleted \n";
}else{
return "There was an ERROR deleting ". $GLOBALS['file']."\n";
}
}// end delete
function switch_default() {
echo "Command not found \n";
help();
}
switch($command) {
case "-h":
echo help();
break;
case "-g":
echo grab();
break;
case "-f":
echo reformat();
break;
case "-l":
echo load();
break;
case "-d":
echo delete();
break;
default:
switch_default();
break;
}// end switch
? >
Many times, I have to execute sequential commands inorder to complete a task. Below is an example of how to do this.
/path/to/command argv1 && /path/to/command argv2
I normally use this sequential order when pulling raw data from a source and then reformatting it for my needs.
15 * * * * /usr/local/bin/pullsource grab && /usr/local/bin/pullsource reformat
You can change your default crontab (crontab -e) by setting the EDITOR environment variable in BASH:
hostname# which vi
/usr/bin/vi
hostname# export EDITOR=/usr/bin/vi
hostname# set | grep EDITOR
EDITOR=/usr/bin/vi
_=EDITOR
hostname#
This afternoon, one of our Epson Stylus Pro 4800 printers developed a maintenance required 0002 error code. The code refers that the Carriage Return Motor or CR Motor has reached the end of its life and should be replaced. At the time this Epson 4800 had printed 16,195 prints and had transferred the print head (carriage) back and forth 4,995,102 times.
To reset the CR Motor count, you have to enter “Service Mode 2″. To do this, follow the following steps.
1. Turn off your Epson 4800.
2. Hold down the Pause, down and menu buttons.
3. Restart the Epson 4800 while holding down the buttons mentioned above.
4. Continue to hold the buttons down until you see “Service Mode 2″.
5. Use the up and down arrows to navigate to clean counts.
6. Locate the CR Motor count.
7. You should see an “Exec” on the screen.
8. Use the right arrow to select “Exec”.
9. Press the menu right arrow one more time to execute the clear command.
10. power off and then power back on your printers. The error should be cleared.
Note: Your print quality may degrade with time. Epson recommends that you replace the CR motor when this error appears.
I’ve been using WordPress for a number of years and decided to switch my permalink structure. It originally was set to the default setting of ?p=100. I wanted to increase my SEO so I changed it to the current format Year / Month / Day / Post-Name. When I switch over, wordpress automatically created a .htaccess file in my webroot folder and locked me out of my website with a Forbidden Error.
Forbidden
You don't have permission to access / on this server.
The .htaccess file that was created looked like this.
< IfModule mod_rewrite.c >
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
< / IfModule >
After chatting with my web administrator, we came to the conclusion that FollowSymlinks in Apache was off be default. I needed to manually turn it on. The new .htaccess file looks like this.
< IfModule mod_rewrite.c >
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
< / IfModule >
Additional Links:
Apache RewriteEngine
WordPress Codex for Permalinks