Script is series of instructions written in plain text file. The script interpreter (i.e. shell, Python, Ruby, etc.) can read this file and act on the instructions as if they were typed at the command prompt. The interpreter also provides a variety of useful programming features to make your scripts ...

learn more… | top users | synonyms (3)

8
votes
7answers
85k views

How do I read a variable from a file?

I want to insert in my script a value (string) that I would read from a text file. For example, instead of: echo "Enter your name" read name I want to read a string from another text file so the ...
8
votes
2answers
17k views

What does outputting to /dev/null accomplish in bash scripts?

Oftentimes I run into small bash scripts that use this sort of syntax in if statements: some command > /dev/null 2>&1 What is the purpose of outputting to /dev/null like that, and what does the ...
8
votes
5answers
777 views

How do you output the filename in find command while using -exec?

I use the following line to find all sub-directories of the PWD and run svnadmin verify on each directory (I already know that they're Subversion repositories) find ./* -maxdepth 0 -exec svnadmin ...
8
votes
2answers
278 views

Referencing variables in a shell script

In a shell script, if I define a variable such as FOO=25, is there a difference between referencing it as $FOO$ and ${FOO}$?
8
votes
3answers
21k views

Store output of command into the array

This is command: pdc status -a 2>&1 | grep 'okay' It gives the following output [okay ]: you are currently listening: 33 [okay ]: you are currently listening: 22 [okay ]: you are ...
8
votes
2answers
22k views

Shell script to move all files from subfolders to parent folder

I've bunch of folders in folder A. I want to move files from all those folders to A. Or I want to cut all files from child folders and paste them in parent folder. How to do that?
8
votes
1answer
59k views

How to make a file executable? [duplicate]

How can I make my file so that I can double click on it, and it runs. It is a .sh script, but I also have files that say: executable (application/x-executable) in the description of what they are. ...
8
votes
3answers
4k views

how to detect a file over internet using ping or similar command?

I have a shell script to download some of my stuff over Internet. How can I know if a file exists over the Internet? Let's say I want to know if http://192.168.1.1/backup/01012011.zip exists or not? ...
8
votes
3answers
28k views

Get wget output to a variable

How can I do it? I am trying it like this RESULT=`wget $URL` P.S. - Also any recommended sources for learning shell scripting?
8
votes
2answers
27k views

.sh script won't run [duplicate]

Possible Duplicate: How do I run .sh files in Terminal? I'm trying to install Craftbukkit on my Ubuntu 12.04 server. However, I'm having issues with step seven, which instructs me to run ...
8
votes
2answers
10k views

Apply icons to bash scripts

I created a script for XChat according to this answer, and I was wondering if there is anyway to apply XChat icon to it.
8
votes
2answers
4k views

How can I convert an iTunes WAV music library to FLAC from the command line?

I have a large music library that is currently managed by iTunes in Windows. When I started out 5 or 6 years ago ripping my music to my PCs I had a fairly basic understanding of audio formats, and I ...
8
votes
3answers
11k views

Ubuntu 14.04 not running Bash scripts in /etc/cron.daily [duplicate]

I have a few scripts (that currently run in a CentOS system) I have moved to a new Ubuntu 14.04 system. These scripts are in the /etc/cron.daily to run once a day. These scripts are to run at the ...
8
votes
2answers
2k views

What is responsible for mounting disks listed in fstab?

What script/init process/whatever is responsible for reading fstab and calling mount, during the boot process?
8
votes
2answers
249 views

How to highlight current screen (or window)?

I'm using two screen setup at work and while it usually helps more than it hurts, I have some issues with it. One of them is problem with trailing focus - sometimes I make mistake of typing on wrong ...
8
votes
3answers
13k views

How can I process multi-line records with awk in a bash script?

example.txt is below Restaurant: McDonalds City: Miami State: Florida Address: 123 Biscayne Blvd Phone: 911 Restaurant: 5 guys City: Atlanta State: Georgia Address: 123 Peachtree Rd Phone: 911 ...
8
votes
3answers
2k views

How can I add a script to nautilus for running selected file as administrator?

How can I add a script to nautilus for running selected file as administrator (not open as administrator)? And if it is possible, I want to run this file as administrator without entering my password. ...
8
votes
1answer
755 views

Execute shell script or command on idle time

I'm searching for the possibility to execute a shell script or command based on idle time in the bash shell. As an example, if I'm in a SSH session to a server of mine and after X minutes of ...
8
votes
2answers
1k views

How to run a script when there is a change in your local IP?

Before marking as a duplicate: this is not about dynamic DNS or similar things. I know how to run a script every time my networks goes up; it is a simple matter of adding a script in the directory ...
8
votes
2answers
235 views

Get the total listening time from the CLI with banshee

Is there a way I can get total listening time from command line? I want to write a script to keep track of how much time I spend listening to music on a daily basis.
8
votes
3answers
11k views

Run (system) script on SSH login and/or logout

I'd like my OpenSSH server to start a script whenever a user logs in using SSH, ideally passing the host name or IP, as well as the user name. Additionally I'd like it to run a script, whenever a ...
8
votes
1answer
2k views

Script Execution at user logout (non root user)

I am in my university labs running ubuntu 12.10 with unity and I don't have root privilleges. I need to run a script at logout. Is this possible? Note: this is probably a duplicate of this question, ...
8
votes
3answers
334 views

How to run a script when a directory is changed by another user?

I know has been a bit of discussion about topics similar to this. But here is what I am basically trying to do. I have a watch directory called watched and whenever a file is added to that directory, ...
7
votes
5answers
1k views

How to send a file as an input to another file?

Through the command shell we can redirect the three standard filestreams so that we can get input from either a file or another command instead of from our keyboard, and we can write output and errors ...
7
votes
3answers
175 views

Same script opened in three different ways produces three different results. Why? [duplicate]

I have a sample script (credit goes to kos): #!/bin/bash cat <(cat /etc/lsb-release) I save this script as somename.sh in my home directory. Now, I try to open this file in three different ...
7
votes
5answers
565 views

how can I take total minutes from time?

My system displayed the time like this 10:42 when i input the command date +%R. I need to take in total minutes of the time. That means like this 642 minutes. Is there any command or shell script for ...
7
votes
3answers
495 views

Display the current date & time in the window's title

Is it currently/technically possible to display the current date & time (ie: digital clock numbers) to the currently active window? Like appending some text from a script?
7
votes
5answers
760 views

Generating an app list from the old installation to run it on the new installation

I want to shift from ubuntu-desktop 10.10 to ubuntu netbook edition 10.10 on my netbook. Currently, the moment I ssh into ubuntu from my ad-hoc network, ubuntu freezes. It always requires a cold ...
7
votes
5answers
441 views

Bash - Check directory for files against list of partial file names

I have a server which receives a file per client each day into a directory. The filenames are constructed as follows: uuid_datestring_other-data For example: ...
7
votes
3answers
8k views

Can scripts run even when they are not set as executable?

I can seem to run scripts (.sh) with and without them being set as executable. So where exactly this matters?
7
votes
2answers
632 views

How can I pass command line arguments to a script through Dash? (14.04)

I recently asked this question about adding a shell script to Dash: In 14.04 how do I run a bash script I wrote without opening a terminal? It worked perfectly. Follow-up question: How can I ...
7
votes
4answers
3k views

Script to Mute an Application

My goal is to be able to mute the Spotify application, not the entire system. Using the command: ps -C spotify -o pid= I am able to find the process ID of Spotify, in this case the ID is "22981". With ...
7
votes
3answers
709 views

Getting internet browsing history from shell

is it possible to use the shell or generate a shell script to find out the browsing history from the browsers installed on the system? thank you
7
votes
2answers
1k views

Batch files renaming w/ filename's shift

I have a ton of files named this way: [name]_[phonenumber]_HH-mm-ss_dd-MM-yyyy.mp3. How can I shift [name] and [phonenumber] to the end of file name, and put the date in the beginning in form of ...
7
votes
1answer
1k views

How to send keystrokes to Chrome in Ubuntu?

I would like my computer to press the Esc key every 2 minutes. How can I do this? With and app or shell script or otherwise?
7
votes
2answers
843 views

How to use zenity file selection

I am new to zenity and I am trying to make a simple script for loading a file using zenity --file-selection and the wc command to get the word count of that file. I have successfully made a form which ...
7
votes
4answers
3k views

How to get longest line from a file?

I'm interested to find out the line number of the longest line from a file. For example, if I have a file with the following content: lalala tatatata abracadabra mu mu mu how can I write a bash ...
7
votes
2answers
26k views

Run shell script on startup or boot

My problem in a nutshell is that I have to run a script every time I use my computer so I'm trying to automate the process a bit. My system has the nvidia gt540m vga card. The card is dual. It has ...
7
votes
3answers
6k views

What is the difference between “source x”, “. x” and “./x” in Bash?

I have one bash source run.sh as follows, #!/bin/bash if [ $# -ne 1 ]; then exit fi ... when I execute it in two ways, there are different behaviors. The first way is, source run.sh It will ...
7
votes
2answers
1k views

Oneliner command to use kill given tcp port number instead of PID?

I often do e.g. sudo netstat -lpn |grep :8088 view the output tcp6 0 0 :::8088 :::* LISTEN 11189/java and then sudo kill -kill 11189 I'd ...
7
votes
3answers
24k views

Create a .desktop file that opens and execute a command in a terminal

I would like to know how to write the Exec command of a .desktop file to open a new terminal and execute a shell script in it. The shell script is working and accessible by all users. When launching ...
7
votes
2answers
12k views

Writing scripts with arguments?

I want to write shell script that takes an argument, and then applies it to files. Specifically, I want to give a term, and then have it compile term.as with mxmlc ("mxmlc term.as"), then run ...
7
votes
4answers
35k views

Is it possible to pass passwords on a shell script?

Long time i am searching for this, i would like to know is it possible to pass passwords in a shell script? Many of the answers returned with no. Recently i read an article stating that how to pass ...
7
votes
2answers
2k views

Getting a script to run on boot, not on login

How can I get a specific script to run (preferably not as superuser) whenever the machine boots, but before login. It can be the last thing to run on boot. I mostly just want the script to work even ...
7
votes
3answers
30k views

How to execute sudo commands with Expect & send commands in bash script?

Can any body let me know how to execute sudo commands with expect. I tried the following but this is not working. Can anyone give me suggestion please? set login "sasuke" set addr "hostname" set pw ...
7
votes
2answers
3k views

Displaying colors in the prompt

How to display my prompt in color? I see a lot of text go up my screen, and a lot of crud. Something like (red)myName(red)@(blue)myMachine:~$(blue) would help simplify things a lot. Much Appreciated. ...
7
votes
3answers
127 views

How to lock screen 30 minutes after unlock [duplicate]

I would like my children to only use the computer for 30 minutes, at which time I would like the screen to be locked. At that point, if I choose to unlock the screen again, I would like the screen to ...
7
votes
1answer
6k views

bash script source: No such file or directory

I have a script that begin like this #!/bin/bash VALKYRIE=~/myProjects/valkyrie source $VALKYRIE/cluster.conf but when I run it it returns line 2: ~/myProjects/valkyrie/cluster.conf: No such file ...
7
votes
1answer
4k views

Bypass “Do you want to…” dialog after clicking script

After I create a bash script and double click it in Nautilus I am prompted with this - Do you want to run "sleepytime", or display its contents? With Run in terminal, Dislpay, Cancel and Run as ...
7
votes
3answers
5k views

Upstart, one job definition to start and one to stop

Hi i just discoverd ubuntu upstart (etc/init/* scripts). And i would like to use it to run a particular application. This app is run via a command line, but there is an argument to start an instance ...