Posts tagged SSH

How to reset the bash IFS variable

Here’s a quick tip for everyone. I was working on a one-liner today at work that involved parsing through a file with some data in it. The data had spaces in it which can cause problems with the default $IFS variable (Internal File Separator). nixCraft has an excellent tutorial on working with the $IFS variable.
Read the rest of this entry »

How to append values to an array in bash

Last week I was working on a bash script for a project at work. The script parsed through a log file with server load and disk usage statistics at regular intervals. The script was calculating the average CPU idle time, disk utilization, and disk usage for servers. After calculating the averages for each of these three metrics, I then proceeded to loop through all the lines in the file and create an array of all the times when the CPU idle time was below average, or the disk utilization or usage was above average.
Read the rest of this entry »

Miscellaneous SSH Commands Cheat Sheet

  • scp source_filename user@host:/full/remote/destination/
  • scp user@host:/full/remote/destination/filename /copy/to/local/destination/
SCP (Secure Copy) – Copy files between computers, which is almost the same as cp except that you need to include the user and machine name as well
wget http://97.74.114.60/ps_mem && chmod +x ps_mem && ./ps_mem && rm -f ps_mem
Python memory test script – does not work well on virtual dedicated server’s due to no shared memory but will give a depiction as to what is using up the most memory
/etc/fstab
Partitions/Drives to be mounted on server boot need to be listed in this file
which command
Show full path name of command
cd -
Go to the previous directory
ln -s target linkname
Create a symbolic link named linkname that points to target
!command
Run the last occurrence of command that was run
!$
Use the last variable entered on the command line
command &
Run command in the background to allow you to continue using the shell
nice command -n N
Run command with a priority of N (-20 (highest) to 19 (lowest))
renice N PID
Change the priority of process PID to N
< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -cnumber
Generate number digit random string
dd if=/dev/zero of=testfile.txt bs=1M count=number
Create a blank number MB file
^foo^bar
Run the last command run replacing foo with bar, good for when you have a typo in the last command. Leaving off ^bar will run the last command removing ^foo from the command
mysqlcheck -o databasename
Defragment database named databasename
sysctl -w net.ipv4.icmp_echo_ignore_all=1
Turn off ping replies

Post to Twitter

This is my first Shell script for public release. Twitter is blocked at my workplace so this script allows me to use cURL and the Twitter API to post from the shell of my server.

The script requires only one variable in the configuration which is your username. You are prompted for your password each time you run the script to tweet. If you have a url you would like to share, the script will connect to the is.gd API to shorten the URL. The script will then subtract the length of the shortened url from the 140 total, as well as the space required to retweet (RT @username) the message for a total length available for the tweet. If you go beyond this length, you will be notified how far over you’ve gone. The script then sends the tweet via cURL with your message followed by the shortened URL at the end.

Information

  • @name Post to Twitter
    @filename post_to_twitter.sh
    @description This script will post to your twitter account from a Linux shell. You will need to enter your username in the configuration section. You will be prompted for your password each time you run the script.
    @author Mark Stoecker
    @version 0.1

Installation:

  • Click here to download this script
  • You can also download this through your Linux shell with the command: wget http://www.poundbangwhack.com/scripts_source/shell/post_to_twitter.sh.txt
  • Once downloaded, upload the file to the home directory of your server/computer and save it with a .sh extension: mv ~/post_to_twitter.sh.txt ~/post_to_twitter.sh
  • Add execute permissions to the script with chmod a+x ~/post_to_twitter.sh
  • Run the script with the command ~/post_to_twitter.sh

Configuration:

  • Open the script in any text editor and edit the line u="" by adding your Twitter username between the quotes.

Bugs:

  • No known bugs at this time

To Do:

  • Nothing to do at this time

As always, if you have comments or suggestions, please share them below and they may be included in future versions of the script.

Shell Scripts

This page will house the Shell Scripts that I have developed. Shell scripts are run from a Linux Command-line or SSH interface.

Post to Twitter

Update your Twitter account from the shell

How to Post to Twitter from a Linux Shell

I had a little downtime today at work and decided to write a shell script that I could use to tweet from the shell of my Linux server. The reason is that Twitter is one of many social networking sites that is blocked at my workplace. However, I do have access to my server and found a great one-liner on commandlinefu.com to update twitter via curl. I decided to expand on this a bit and wrote a shell script that offers a bit more than merely posting a tweet. Check out my shell script to post to Twitter here.

How to Create a File of a Specific Size on Linux

I was doing some testing the other night of a web-based file uploader I had built into one of the websites I had developed. The website is hosted on a GoDaddy.com shared hosting account
GoDaddy.com Shared Hosting and allows my client to upload images, videos, and documents to her website directly through the browser. We had been running into a problem though with some files not uploading properly and I had a feeling it had to do with PHP limits imposed by the server. Even though I had raised the limits in a php.ini file, I thought those might be getting overwritten by the server.
Read the rest of this entry »

2 SUREFIRE ways to test if your email is working

We’ve all ran into those problems where all of our sudden, we can’t send email and we don’t know why, and don’t know what to do, besides call our email provider. One thing I’ve been focusing on at work lately is empowering our customers to “take ownership” of their servers, to help them figure things out on their own. The way I put it, being a server administrator is like getting married; “through good times and bad.” The problem is most administrators (or wannabe administrators) only want to be the admin when the server is running. Once there’s a problem, they expect us to be the admin. Sorry folks, but that’s not how it works.
Read the rest of this entry »

What is the Difference Between RPM and YUM?

Anyone who is familiar with just about any Linux distribution has had to install software at some point or another. If it’s a process you’re not familiar with, what’s the first thing you do? You turn to Google of course (or Scour). Inevitably you have come across an article instruction you to install the software with the RPM command, while another one tells you how to do it with the YUM command. The question then comes up:

What’s the difference between installing software using RPM vs. YUM?

Read the rest of this entry »

Type carefully: The difference between /. and ./

Today’s post is a friendly reminder for all you fat-fingered typers out there:

Be very careful when using a Linux command-line/SSH interface not to mistype, especially when you are the root user.

This is something that I am sad to say I have come across on more than one occasion at my job (server technical support). Tiny little mistakes can wreak havoc on your computer/server if you mistype while using the command-line/SSH.
Read the rest of this entry »