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

learn more… | top users | synonyms (2)

2
votes
1answer
207 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
33 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
510 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
373 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
359 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
371 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
280 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
210 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
697 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
356 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
190 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
192 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
231 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 ...
2
votes
1answer
94 views

Linux shell - unexpected error

I'm new to the linux & command world. I have two directories, one called pasta (which contains 3 files) and another one called pasta2 (with nothing inside). I'm trying to move all 3 files from ...
5
votes
1answer
293 views

Variable in sed

I have a file that contains filenames with absolute path. In the middle of that path, is a variable directory, whenever I hard code the variable part, it works fine, but when I replace it with the ...
3
votes
4answers
662 views

How to prepare files for rsync on a case insensitive filesystem?

I am transferring a large number of files on a HFS+ filesystem. The files are currently on ext2 partitions. I have conflicts due to case insensitivity of the target partition (HFS+). I want to ...
2
votes
3answers
101 views

What is the language that appears on the first line of a script? [duplicate]

Bash scripts start with the following line #!/bin/bash # Rest of script below ... In bash the # character is the start of a comment, but #!/bin/bash is definitely not a comment, therefore it isn't ...
3
votes
2answers
244 views

How to make /etc/init.d script act like it's launched under X?

I'm trying to track down some quirkiness with a Java application that misbehaves when launched via a startup script in /etc/init.d , but runs fine when you open a GUI terminal window and run it ...
2
votes
1answer
969 views

Linux nuisance: /dev/stdin doesn't work with sockets

Linux has this blitheringly annoying peculiarity that /dev/stdin won't work with sockets - it is hardcoded to return ENXIO. Try this: socat TCP-OPEN:localhost:1234 EXEC:cat\ /dev/stdin,nofork ...
4
votes
3answers
1k views

How do I create a bash script that sums any number of command line arguments?

How would I create a bash script that the user can use to sum any amount of command line arguments? For example, say my script is called sum: sum 3 3 sum 3 5 8 sum 9 8 21 38 And so on.. I ...
3
votes
2answers
537 views

Converting Webserver Logged IP Addresses to DNS

I'm trying to use a bash script to process a webserver log file and replace any IP's it finds with their corresponding DNS hostnames. An example entry of a single line from the log file is: ...
5
votes
3answers
621 views

How to start a script with clean environment?

I tried the following but it doesn't seem to work: $ cat script.sh #!/bin/env -i /bin/sh /bin/env $ script.sh /bin/env: invalid option -- ' ' Try `/bin/env --help' for more information.
1
vote
3answers
1k views

compare files line by line and create new one bash programming

I have two text files. File 2 has logs over 1,000,000. File 1 has IP addresses line by line. I want to read file 2 lines and search these lines in file 1, I mean: file 1: 34.123.21.32 45.231.43.21 ...
3
votes
4answers
220 views

Does cron jobs per se represent a significant burden on a modern system?

I'd like to run a pretty simple script (is there a dir with name x in dir y if so move it to dir z–and x will only be there about once a day) every 15 seconds or so (one minute divided into 4*15 ...
4
votes
1answer
226 views

echo $? returning 0 instead of 1

[root@server ~]# bash << eof > cat adsfasdf > echo $? > eof cat: adsfasdf: No such file or directory 0 Could anyone please explain why it is returning exit status 0 instead of 1?
2
votes
2answers
2k views

run a script at shutdown in Debain

I am using Debain wheezy. My problem is , I am using a limited 2.5 GB net connection. My idea is simply running a script as #!/bin/bash date >> ~/mydatausage.txt ifconfig -a >> ...
2
votes
1answer
304 views

Find a particular nesting of directory names, e.g. …/project/dir1/dir2

I'm having some issues dealing with the find command; I don't know the syntax for it very well and I need to use it in a script to find a specific directory structure that could be located anywhere. ...
1
vote
1answer
803 views

Run an executable with a Shell Script

I have mplayer installed and I want to create a simple shell script that runs in bash and executes mplayer * in the current directory. So, how to call upon mplayer in the shell script? I am a newbie ...
4
votes
1answer
544 views

Bash capture any error like -e but don't exit, do something else

I want to set a flag in a shell script (bash) so that if anything returns non-zero, a flag is set (i.e. set a variable like errors="True"). So far, I've thought of calling the script with ...
2
votes
1answer
355 views

Exiting a Bash script when a sudo child quits

I'm trying to launch a couple of sub-programs from a bash script and then wait on either of them to quit before quitting the other and exiting the script. CMD1PID= CMD2PID= exit_trap () { ...
2
votes
2answers
94 views

scripted pdf code review

What I try to achieve I need to review a bunch of C source code spread out into dozen of directories. I already have a bash script which does the following: It searches for all source codes in the ...
0
votes
3answers
3k views

Convert Month Number to Month Name

is there a way to convert month number to name? example: 2013-10-22 will become Oct 22 I don't have the GNU date and my OS is AIX.
0
votes
0answers
36 views

Symbolic link path [duplicate]

Hi I want to find out the path of symbolic link. I want to make a script for that but I can not find a command that will print the path of symbolic link. I want to write a script with directory as a ...