Linux Blog

Coppermine Photo gallery Upload Script

Filed under: Shell Script Sundays — TheLinuxBlog.com at 9:15 pm on Sunday, May 31, 2009

This week I bring you a script that I helped Kaleb (who has written posts here before) write. Well, I got him started with it, using curl and he rolled with it and finished it up. Here is the script:

#!/bin/bash
# Script to Upload to http://kporter.homelinux.com/~kaleb/cpg14x
# Written by Kaleb Porter May 23 2009
# with help of www.thelinuxblog.com
# email: porterboy55@gmail.com
# if you wish to use this code for something else please give me credit
 
IMAGE="$1"
URL="http://kporter.homelinux.com/~kaleb/cpg14x/upload.php"
DA=`date '+%d%b%y-%N'`
# If the user does not specify a file or url
if [ -z "$1" ]; then
echo "You did not give a file to upload"
echo "Takeing a screenshot in 3 Seconds..."
sleep 3
scrot $DA.png
IMAGE=$DA.png
fi
FI=`echo "$IMAGE" | grep '^[a-z]*://'`
AL=2
FIUP=`curl -s -F control=phase_1 -F blaa=continue -F file_upload_array[]=@$IMAGE $URL | grep unique_ID | awk -F\" '{print $6}'`
URLUP=`curl -s -F control=phase_1 -F blaa=continue -F URI_array[]=$IMAGE $URL | grep unique_ID | awk -F\" '{print $6}'`
 
#Get the title for the image from the user and change all the spaces to "%20"
echo "Enter a title for the image"
read TITLE1
TITLE=`echo $TITLE1 | sed 's/ /\%20/g'`
 
#Get the Description for the image from the user and change the spaces to "%20"
echo "Enter a discription"
read DES1
DES=`echo $DES1 | sed 's/ /\%20/g'`
 
#Get the keywords for the image from the user and change the spaces to "%20"
echo "Enter keywords (separated by spaces)"
read KEY1
KEY=`echo $KEY1 | sed 's/ /\%20/g'`
 
if [ -z "$FI" ]; then
 
UNIQUE_ID=$FIUP
#echo "Choose the NUMBER value for the album  you want"
#curl -s -F control=phase_2 -F unique_ID=$UNIQUE_ID $URL | awk '/name="album"/{disp=1} {if (disp==1) print} /<\/select>/{disp=0}' | grep 'value="[0-9]"' | sed 's/<option//' | sed 's/<\/option>//' | sed 's/>//'
#read AL
curl -o /dev/null -d "control=phase_2&unique_ID=$UNIQUE_ID&album=$AL&title=$TITLE&caption=$DES&keywords=$KEY&blaa=continue" $URL
exit 0
else
 
# If the image is from a URL
UNIQUE_ID=$URLUP
#echo "Choose the NUMBER value for the album  you want"
#curl -s -F control=phase_2 -F unique_ID=$UNIQUE_ID $URL | awk '/name="album"/{disp=1} {if (disp==1) print} /<\/select>/{disp=0}' | grep 'value="[0-9]"' | sed 's/<option//' | sed 's/<\/option>//' | sed 's/>//'
#read AL
curl -o /dev/null -d "control=phase_2&unique_ID=$UNIQUE_ID&album=$AL&title=$TITLE&caption=$DES&keywords=$KEY&blaa=continue" $URL
exit 0
fi

If there are any questions you can pretty much read the Shell Script Sundays column and figure out everything you need to know. Now that the upload script works, and tries to take a screenshot with scrot, the next step is a check to see if scrot exists, if it doesn’t a check for import, if not an error message.

It really does amaze me at the capabilities of the shell. Especially how mashable it is and how you can combine it with pretty much anything, this script is a great example of combining the power of the shell with the intrawebs. Well, I hoped you learned something, and as always if you have any questions, you know where the comment box is.

– Owen.

Managing Services on Fedora

Filed under: Linux Software — TheLinuxBlog.com at 12:01 am on Wednesday, July 2, 2008

Fedora is a great desktop system, it has a pretty good services manager called service. It can be used to turn on, off and restart most services that run on the system. Should you want to manage running services all you have to do is type:

service[service name] [stop | start | restart]

If you don’t know the service name it can normally be found by issuing the –status-all switch. Doing so will output a long list of services so you may want to grep it or use a pager such as less:

 [root@linux-blog ~]# service --status-all | less
 
[root@linux-blog ~]# service --status-all | grep snmp
capi not installed - No such file or directory (2)
JAVA_EXECUTABLE or HSQLDB_JAR_PATH in '/etc/sysconfig/hsqldb' is set to a non-file.
snmpd is stopped
snmptrapd is stopped

While service is a great utility to manage services it does not stop them from running at startup. To manage services that start up when you boot you can use a handy little dialog script called “ntsysv”:

[root@linux-blog ~]# ntsysv

This will give you a nice dialog which is intuitive and similar to those of text based installers. Select the services you want to start up and then tab over to OK. I turn a lot of services off that I don’t use, if you’re unsure of what you need, try stopping it with the services command first and see if anything breaks. If after test it works well just turn it off.

Since I don’t use SELinux on my development machine, I always turn off setroubleshootd. I used ntsysv to stop it from starting at bootup and if I need it I can use the service command to start it.

Here is a screenshot of ntsysv in action:

managing services with ntsysv on Fedora

Using SSH as a Proxy

Filed under: General Linux,Quick Linux Tutorials — TheLinuxBlog.com at 2:46 pm on Tuesday, April 15, 2008

A helpful reader left a comment on this blog about using SSH as a Socks Proxy. Here is how to do it.

ssh -D [source port] [host]

Thats it, once your logged in you are good to go.

Now, the problem I ran into was making Firefox use this proxy. I found a great extension called SwitchProxy which can be installed from the extensions site. Once installed, you can easily switch between proxies. This is really useful to use while at a coffee shop.

Check out the screenshot of the toolbar that it installs (click for a larger image):

Using SSH as a proxy on Linux

It makes it really easy to turn the proxy on or off. One day if there is interest I might try to extend this to establish the SSH connection.

Checking your battery life from the shell

Filed under: General Linux,Linux Hardware,Quick Linux Tutorials — TheLinuxBlog.com at 8:46 am on Tuesday, December 11, 2007

I’ve often thought to my self “Wouldn’t knowing how much battery life I had be nice.”

Now when a window manager is open, this isn’t a problem. But when your just in a terminal it can be a bit of a problem. If you don’t get the gist of it heres an example, if I’m just in a terminal writing an article, or programming in VIM on battery life. Now I no longer have to execute the following command and guess how much life I have left:

 cat /proc/acpi/battery/BAT1/state

I simply run the command:

yacpi

It tells me all kinds of information about my power usage, what the current temperature is, am I plugged in, what CPU governor I’m using. Its a really neat tool. I would recommend for everyone to install it. Worst case scenario it can be used when the system is undergoing maintenance, or if you left your box sitting in the other room and need to check the battery live via SSH. Check out the screenshot:

YACPI Screenshot

To install it it will vary by distribution. I’m sure Debian has it in its XXXX number of packages which means Ubuntu probably has it too. To install on other distributions such as Gentoo or Slackware you’ll need the source. You can acquire the source from here: http://freshmeat.net/redir/yacpi/55486/url_homepage/yacpi
You’ll also need libacpi which can be found here: http://freshmeat.net/projects/libacpi/?branch_id=70062
Make sure you compile libacpi first, or the make will fail for yacpi.

That’s it, once you download the package and install or download and compile the source you’re good to go. Have a good time checking the battery life from the shell. Try doing that in DOS!

Slackware-Current Xfce 4.4.2 Updates

Filed under: General Linux,Linux Software — TheLinuxBlog.com at 1:33 pm on Wednesday, December 5, 2007

Slackware 12 - Current, Firefox, Xfce 4.4.2 Screenshot.I upgraded my Slackware Box to Slackware-Current yesterday and there are many updated packages. Here is the Slackware Current Changelog.

Included is Xfce 4.4.2, this is the newest Xfce and has many bug fixes and a minor security bug fix in terminal. For the entire list you can look at the Xfce – 4.4.2 changelog

Firefox 2.0.0.11 is in this release which is good because sometimes the current repository contains older versions of Firefox.

The screenshot is just a screenshot of the GetFireFox page. Also, you will notice the nice transparencies feature of Xfce. Click it for the larger version.