Bash Scripts For Linux

View previous topic View next topic Go down

Bash Scripts For Linux

Post by Jim on Sun Mar 27, 2011 12:31 pm

I made a few scripts for Linux that I've been using pretty often, so I thought I'd share them here.

This first script is just a one liner for doing a basic screen capture using ffmpeg.
To use it you'll need to install ffmpeg first, it's in the standard repositories for most Linux distributions and can be installed by typing the following line into the terminal -

sudo apt-get install ffmpeg

In order to use the script you'll need to paste the code into a file and then save it, afterwards you'll have to make the script executable by typing this into the terminal-

sudo chmod +x 'TheNameAndPathOfYourFile'

Now you'll have to open the file in terminal, you can just type in the file path and name, or if you're lazy like me, you can just drag and drop the file into the terminal window and press enter. The capture output file can be found in the same location as the script file.

SGrab Script

#!/bin/bash
ffmpeg -f x11grab -s 1280x800 -sameq -r 30 -i :0.0 `dirname $0`/screenCapture.mp4


This next script also uses ffmpeg, it's a video file converter, it maintains the video and sound quality and just changes file type. This script uses zenity to create a basic GUI, so you can run it by just double clicking the icon rather than running it in terminal (assuming you've made the file executable).

VCon Script

#!/bin/bash
zenity --info --text="Welcome to Vcon video file converter, please choose a source file"
SourceFile=$(zenity --file-selection --title="Vcon - Source file")
zenity --info --text="Please choose a file destination, include the file name and proposed extension"
DestinationFile=$(zenity --file-selection --save --title="Vcon - Save file")
clear
gnome-terminal -e "ffmpeg -i $SourceFile -sameq $DestinationFile"
notify-send " Vcon finished"


The last script is for commenting and uncommenting the jack sound modules in pulseaudio's default.pa file, if you're using the jack modules with pulseaudio you often have to activate/deactivate them in order to change various settings such as the audio input device. It's really annoying having to find the file and edit it just so you can change the levels or select an audio device.
You'll need to have jackd and pulseaudio-module-jack installed, and you'll also need to edit the pulseaudio default.pa file to include the jack modules.

Steps for editing default.pa

firstly->
turn volume up full! (full full, go into sound preferences and put it into overdrive!)
edit->
/etc/pulse/default.pa
copy->
load-module module-jack-sink
load-module module-jack-source
underneath->
#load-module module-null-sink
#load-module module-pipe-sink

Phew - after all that you can finally run the script, you'll need to run this one in the terminal as it has no GUI, it will simply flip between activating/deactivating the jack modules-

Jack-It script

#!/bin/bash

defaultFile="/etc/pulse/default.pa"
lineSink="load-module module-jack-sink"
lineSource="load-module module-jack-source"

lineGrep=`grep "#$lineSink" "$defaultFile"`

echo ""
for ((i=0;i<${#defaultFile}+35;i++))
do
echo -n "*"
done
echo ""
echo "* Editing Pulseaudio Settings -> $defaultFile *"
for ((i=0;i<${#defaultFile}+35;i++))
do
echo -n "*"
done
echo ""

if [ "$lineGrep" == "#$lineSink" ]
then
echo "Activating -> $lineSink & $lineSource"
sudo sed -i "s/`echo "#$lineSink"`/`echo "$lineSink"`/g" $defaultFile
sudo sed -i "s/`echo "#$lineSource"`/`echo "$lineSource"`/g" $defaultFile
else
echo "Deactivating -> $lineSink & $lineSource"
sudo sed -i "s/`echo "$lineSink"`/`echo "#$lineSink"`/g" $defaultFile
sudo sed -i "s/`echo "$lineSource"`/`echo "#$lineSource"`/g" $defaultFile
fi

echo "Killing Pulseaudio"
killall pulseaudio
echo ""


That's it, enjoy, if you want any help with them, give me a shout ^_^

Jim
Admin

Posts: 286
Join date: 2009-09-24

View user profile http://www.sonodrome.co.uk

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

Permissions in this forum:
You cannot reply to topics in this forum