Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

learn more… | top users | synonyms (2)

1
vote
3answers
103 views

Automating pipes?

I find myself using basically the same line over and over again: cat file | command1 | command2 | command3 > file Is there a way I can put all these pipes into one script, so I can just run ...
6
votes
2answers
825 views

Piping data to a process's stdin without causing EOF afterward

I have an executable that starts a user-interactive shell. I would like to, upon launch of the shell, inject a few commands first, then allow the user to have their interactive session. I can do this ...
1
vote
3answers
2k views

Line 4: $data: ambiguous redirect when using passwordbox

I want to create a passwordbox using the dialog package. #!/bin/bash data=$(tempfile 2>/dev/null) trap "rm -f $data" 0 1 2 5 15 dialog --title "Password" \ --clear \ --passwordbox "Enter your ...
12
votes
3answers
522 views

How do I wait on a program started in another shell

I have a program that does a large a amount of work (takes about 4-5 hours) that gets started by cron when all the data it works with becomes available. Sometimes, when I am waiting for it to finish, ...
3
votes
2answers
305 views

Sorting Photos using shell script

The majority of my photo files have the following naming convention / format IMG_20131204_120000.JPG, showing date and time the photo was taken (iPhone/Apple naming convention). However, not all my ...
-3
votes
1answer
230 views

Count number of sessions and email as a body

I want to create a script to achieve followings : 1.login to Essbase MaxL essmsh -l admin password on localhost; 2.Count the number of lines in the output of command display session all; display ...
0
votes
1answer
4k views

How to Create a Unix Executable File [closed]

Is it possible to create what the Mac Finder specifies as a "Unix Executable File" and run it in Terminal like any other command instead of creating a .sh or .command file? If so how and where can I ...
2
votes
1answer
1k views

Change executable reference for app icon in in GNOME 3 launcher

I've created a custom script to launch VirtualBox that replaced the original script in ¸/usr/bin/¸. So running VirtualBox in a terminal launches my script. However, pressing super key and type ...
1
vote
0answers
248 views

Shell script to backup VMware VM's, exporting each VM to a list then asking user intput

What I'm Trying To Accomplish: Get list of Virtual Machines ".vmx" file and place in variables Give the user and choice of which VM to backup Use "ovftool" to produce an export of the chosen VM to ...
1
vote
1answer
89 views

How to resolve a hostname via nsswitch?

I want to test in a script whether a hostname resolves to something other than 127.0.0.1 as a pre-flight test for an install script. The tools I know (dig, nslookup) specifically query DNS. In my ...
3
votes
1answer
152 views

Find directories with a certain name

How can I loop through each directory recursively and whenever it finds a folder called VIDEO_TS, let Genisoimage convert that folder's content to an dvd-video iso image, the name of the iso would be ...
3
votes
3answers
178 views

Why is my condition always false?

I tried to write a script which creates a user. First it needs to check if: root is running if user maybe already exists I Also tried to set the password equal to the username which was typed ...
8
votes
3answers
327 views

POSIX compliant way to work with a list of filenames possibly with whitespace

I have seen Bash scripting guides suggesting the use of array for working with filenames containing whitespace. DashAsBinSh however suggests that arrays are not portable so I am looking for a POSIX ...
2
votes
2answers
87 views

OS X: how to keep the computer from sleeping during a http connection

An application I use downloads data from a specific server, and I need it to sleep after the download has finished and the socket is closed. However downloads take place at random days, the app that ...
1
vote
2answers
324 views

How to invoke a shell built-in explicitly?

I want to customize the functionality of cd command as per my needs. I define following function - function cd () { cd "$@" && pushd "$@"; } The intent of this function is to automatically ...
7
votes
3answers
30k views

How to rename multiple files in single command or script in Unix? [duplicate]

I have the below list of files aro_tty-mIF-45875564pmo_opt aro_tty-mIF-45875664pmo_opt aro_tty-mIF-45875964pmo_opt aro_tty-mIF-45875514pmo_opt aro_tty-mIF-45875524pmo_opt that I need to rename to ...
3
votes
1answer
113 views

script to remember dir and always cd to it instead of the root dir

How can write a script to change to a given directory but also remember it so that when you do cd it always changes to that directory ? #!/bin/bash setdir() { cd $1 # remember the directory ...
5
votes
3answers
1k views

Using `kill -s 0 $pid` vs `[[ -e /proc/$pid ]]` to detect if PID is running

One of the idioms often used to check if process is running is to use kill -s 0 $pid. My question is, does it have any upsides over using [[ -e /proc/$pid ]] construct? The script I'm writing is ...
4
votes
2answers
543 views

Create sub-directories and organize files by date from file name

I have been using the following script to organize my photos into "Date' Directories: for x in *.JPG; do d=$(date -r "$x" +%Y-%m-%d) mkdir -p "$d" mv -- "$x" "$d/" done This script works ...
1
vote
1answer
56 views

auto-delete fluxbox menu entries

I want to delete fluxbox menu commands that are in the form of - [exec] (foobar) {/usr/lib/xscreensaver/foobar -root} and there are 50+ commands to be deleted. But, how do I do it please? I need a ...
2
votes
1answer
202 views

Can't echo or create a symbolic link to a file with special characters in its name inside bash script

I'm trying to create a symbolic link to files with the following naming convention: .$abc$namehere.zip;1 As can be seen, it has the following special characters in it: . $ ; In my bash script I ...
5
votes
2answers
1k views

Get the PID of file creation

I am writing a bash script that creates 5 files with the extension ".P" and write a line of "something" into them. "P" represents a number and it's the PID of the process that creates the file. How ...
11
votes
2answers
2k views

find and remove duplicates in a directory

I have a directory with multiple img files and some of them are identical but they all have different names. I need to remove duplicates but with no external tools only with a bash script. I'm a ...
-3
votes
1answer
32 views

Need help with this script [closed]

I'm supposed to write a bash script that has as an argument a path to a directory which contains a file named checking.txt. It needs to return the following exit codes: 4, if the directory doesn't ...
1
vote
3answers
321 views

Creating a file counter that includes hidden files

As part of a programming assignment I need to create a piece of code that will count the number of files and directories (including hidden) recursively. I'm not allowed to use the commands -R, find or ...
0
votes
0answers
114 views

Shell Script : Check for all the source files in different paths

This is the naming convention of the file. <yearmonthdate>_<sourcesystem>_<totalnoofpartsof file>_<subject area>_<part number>.dat (or .dat.gz) First part is Date, ...
0
votes
1answer
509 views

Meaning of different options used while running a shell script

I was reading a shell script and I found the below command there. I tried searching on Google thinking attach, force and delete are the options used while running a script. But failed to find ...
9
votes
4answers
7k views

how do I trim each line in bash?

I would like to remove all leading and trailing spaces and tabs from each line in an output. Is there a simple tool like trim I could pipe my output into?
2
votes
3answers
372 views

How can I tell echo/printf in Bash to swallow escape codes, based on a condition?

I have a Bash script that is being run interactively and as a cron job. When run interactively it outputs colored text on the terminal. However, when run in cron it doesn't have a terminal and ...
2
votes
1answer
118 views

Check for existence of files prior to acting on them

In one of my processes I check for existence of files older than 31 days, and then do stuff with them. find /my/directory/*txt -mtime +31 -exec ls -l {} \; All this is well and fine if files are ...
5
votes
3answers
353 views

removing redundancy from output columns

What is a *NIX way of removing redundancy in a case where I have pairwise comparisons like these in two columns A B B A A C A D C A D A B C C B A B and B A ...
2
votes
5answers
2k views

Bash: What is the use of type (Bash builtins)?

I came across a command in Bash script in which I found: find /var/log/abcd -type f The above command was in context of cleaning the log files. I know what find does. After having seen -type f, I ...
0
votes
2answers
370 views

Two or more yes/no questions in a script?

I'm writing a bash script which has a "yes/no" question in it, but now I want to have another yes/no question in it. The script can only cope with one yes/no, so how can I have two, or more, yes/no ...
-2
votes
1answer
100 views

How to create shell script command so that it will self-detruct after performing it's task? [closed]

I want to make command run in Ubuntu 13.10 as soon as I login. I know for that I have to add certain command in ~/.profile file. That's not the problem. I want to certain line of that ~/.profile ...
1
vote
3answers
188 views

Filtering a result from a command

I am having trouble writing a little program; when I run the following command from my program: gsettings get org.gnome.desktop.background picture-uri I get: ...
1
vote
2answers
1k views

How to round a float value to int in bash

I will get value like 2743410360.320 and I want value like 2743410360 to a variable. I tried INTValueOfGB=$ echo "($gb+0.5)/1" | bc But I am getting (standard_in) 1: syntax error
6
votes
1answer
2k views

How to write bash script to configure my displays when HDMI is plugged in or unplugged

I have a notebook running Kubuntu Precise (12.04) which I occasionally use for watching videos. When I do, I plug in an HDMI cable connected to an A/V receiver with an HDMI monitor attached to it. ...
1
vote
1answer
278 views

Grep Wvdial output while it is running

I want to grep the output from wvdial while wvdial is running. Actually I want to fire a task when the modem is connected. I want to do this in the following way: grep string "IP address", if it is ...
1
vote
3answers
163 views

Extracting mail addresses

I have a file that contains lines like this: user=<xxxxxxx@asd.com.tr>, user=<yyyyyyy@asd.com.tr>, user=<zzzzzzz@asd.com.tr>, user=<ccccccc@asd.com.tr>, ...
1
vote
1answer
209 views

How do I download PDFs from PubMed, given their IDs?

I have PubMed IDs for files I need to download from the PubMed site in .pdf format. I tried this script: #!/usr/bin/env bash Link="http://www.ncbi.nlm.nih.gov/pubmed/" ID=(10021369 ...
0
votes
1answer
310 views

need to display hard error , transport error & soft errors above 2

iostat -En | nawk '/Hard Errors/ {line=$0;gsub(/.*Hard Errors:/,""); \ if($1>2) printf("%s\n",line); }' The output of this is c0t1d0 Soft Errors: 0 ...
0
votes
2answers
1k views

Using `ls` recursively without -R

I am trying write a shell script that has output similar to ls -R without using the option -R. This is part of a programming assignment that forbids me from using -R, find and du. I need to identify ...
0
votes
1answer
118 views

In shell script, execute a command only if the source is newer than the target

I'm looking for a simplified version of this: dep=0 if [ ! -e targetfile ] then dep=1 elif [ targetfile -nt sourcefile ] then dep=1 fi if [ $dep -eq 0 ] then echo "Already up to date" ...
0
votes
1answer
696 views

Script for running sequential job

I started recently to learn using Linux. I want to write a script in bash shell to run a serial job on a cluster. I have been searching for hints and instructions on how to write such a script. I ...
1
vote
1answer
349 views

Execute command on remote host fails

I'm trying to execute some commands on remote host like this : ssh -t -t -l user 172.20.20.20 <<EOF pid=$(ps -ef | grep [a]pp-management | awk '{print $2}') && kill -9 $pid && ...
7
votes
3answers
2k views

Bash: interactive remote prompt

I have a script which connects to a remote server and check if some package is installed: ssh root@server 'bash -s' < myscript.sh myscript.sh: OUT=`rpm -qa | grep ntpdate` if [ "$OUT" != "" ] ; ...
1
vote
1answer
188 views

Copying wallpaper images into a single folder

In my ubuntu 12.04 set-up, there are lots of wallpaper images in the directory /usr/share/wallpapers. For example, one might be usr/share/wallpapers/Leafs_Labyrinth/contents/images/1600x1200.jpg ...
1
vote
2answers
191 views

Count entries for each directory in tree

Say I have the following tree: root: d foo d bar /foo: d A - tmp.txt /bar: d B - tmp2.txt /foo/A: - tmp3.txt /bar/B: d = directory and - = file I need to answer the following question: which ...
2
votes
5answers
227 views

Read contents in a line in bash

I have a file with contents in this order which is separated by space 4096 1230 4560 1024.... n How can i read each number and pass it on to another command, eg divide each number by 1024.
3
votes
1answer
331 views

Strip most frequent words from text

I have a simple problem, but unfortunately I don't know where to even start (I'm just starting out). So, what I want to do is ultimately increase my vocabulary. I got the idea to strip the most ...