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
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
Posted by dmccoy | Posted in Applescript, Code, OS X | Posted on 10-11-2009
tell application "iChat"
tell application "iChat" to set messagelist to get status message of every buddy
where status is not offline
set msglistcount to count messagelist
set theMessageList to {}
repeat with x from 1 to msglistcount
if item x of messagelist is not "" then
copy item x of messagelist to end of theMessageList
end if
msglistcount = msglistcount - 1
end repeat
set newStatus to some item of theMessageList
set status message to "i'm in your internets stealing your status messages : " & newStatus
end tell
Posted by dmccoy | Posted in Command-Line, Linux, Ubuntu | Posted on 23-09-2009
If you have several servers to manage, having them set with the same date and time is very important.
NTP stands for Network Time Protocol.
ntpdate – set the date and time via NTP
sudo ntpdate NTPServerAddress
or if you want to use ubuntu’s time server.
sudo ntpdate ntp.ubuntu.com
If you want to use multiple time servers, you can use a command like this. Where the new time server follows the address of your current server.
sudo ntpdate ntp.ubuntu.com time.apple.com
Links:
NTP Pool Project
Ubuntu Time Synchronization with NTP
Posted by dmccoy | Posted in Command-Line, Linux, OS X, Ubuntu | Posted on 21-07-2009
For most server administrators doing system updates or installing patches via a command shell is normal, but for the average user trying to patch his new system, this task might be a little difficult. Opening a terminal and downloading a file, just by typing in a few words, is not as simple as clicking a download icon on a website, tho, once you learn how to use Wget or cURL, it will be.
From my understanding, Wget is a stand-alone application, that is command-line only. And, cURL is a cross-platfrom API library called libcurl. Personally, I like Wget better then cURL, but that’s just because I am bias.
If you want to know all the nitty-gritty differences, check out curl vs Wget.
Wget – The non-interactive network downloader. (I refer to it as, WWW Get or Web Get).
wget [option]… [URL]…
curl – transfer a URL
curl [options] [URL...]
How to download a file with wget:
wget http://domain.com/path/to/file.zip
How to download a file with cURL:
curl -O http://domain.com/path/to/file.zip
or
curl http://domain.com/path/to/file.zip > file.zip
After I’ve determine which interfaces are active on my computer(s), I can use this script to report back the IP address of said interface.
# input String ("en0")
# output String IP
function get_network_interface_ip($interface) {
@exec('/usr/sbin/ipconfig getifaddr '. $interface, $retval);
return $retval[0];
}// end get_network_iterface_ip
echo get_network_interface_ip($interface);
I use this script, after I determine what available interfaces the computer has, to report which interfaces are active.
# input String ("en0")
# output "NULL or "Active"
function check_interface_activity($interface){
@exec('ifconfig| awk \'/flags=|media|inet / {if (substr($2, 1, 6) == "flags=") printf("\n%s ", $1);
else if ($1 == "inet") printf("%s ", $2);
else if ($1 == "media:") printf(substr($0, 9))}\' | awk \'$1 ~ /^'.$interface.'/\' | awk \'{print $7}\'',$retval);
return $retval[0];
} // end check_interface
echo check_interface($interface);