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

learn more… | top users | synonyms (1)

-3
votes
2answers
241 views

Need a shell script which should send a mail to me once every 20 days

Can some one tell me the logic or the entire script to create a shell script to send a mail to me once every 20 days
0
votes
3answers
421 views

How do you create and execute a bash script which calls an executable from higher folder?

I'm attempting to write a very simple script which calls an executable from a higher level folder. If I were just typing the command into the console, I would type ../filenamehere {options} ...
2
votes
1answer
96 views

shell script to append ID for newusers command

I am in the process of creating 60 users locally in a linux machine. I wanted to do it automatically and so I found I can use the newusers command to add the users in batch. I have the users and ...
0
votes
0answers
319 views

LFTP mirror upload only non existing files to remote directory

Every 5 minutes some new files are downloaded via lftp to a local directory. I need to upload to another ftp only the non existing files. My script so far is: #! /bin/bash today=$(date +%Y%m%d) ...
3
votes
1answer
171 views

Array Cartesian product in bash

Is there a way to generate cartesian product of arrays without using loops in bash? One can use curly brackets to do a similar thing: echo {a,b,c}+{1,2,3} a+1 a+2 a+3 b+1 b+2 b+3 c+1 c+2 c+3 but I ...
1
vote
2answers
92 views

Meaning of the following linux commands

cat "$1" > /tmp/file.$$ 2>/tmp/file0.$$ grep "*" /tmp/file.$$ >/tmp/file0.$$ I understood that in the cat command, if an error occurs, the error will be shown in file0.$$ and if it ...
3
votes
2answers
177 views

How to find frequency of occurrences of strings contained in a file?

I have a file that contains a list of URLs of the form EDIT http://www.google.com/absd/siidfs/kfd837382$%^$&, www.google.com, google.com yahoo.com/list/page/jhfjkshdjf... I ...
0
votes
2answers
60 views

need help in making script [duplicate]

I want to automate one task in UNIX and make one script. There is directory in which everyday 2 files comes and that files come anytime in between 10 pm to 1 am. file name is ...
3
votes
1answer
59 views

Using Bash to write to a device in /sys?

I have one of these: Basically, it's a USB device with three LEDs (red, green, and blue). The Linux kernel has supported this device through the usbled module for quite some time now. However, I ...
3
votes
1answer
138 views

Script to find the default Desktop Environment?

Assume a Linux Desktop Environment system is installed. When powered on and credentials entered, whatever Desktop Environment is started i would consider the default Desktop Environment. The user may ...
9
votes
2answers
265 views

Are quotes needed for local variable assignment?

Can I safely omit quotes on the right side of a local assignment? function foo { local myvar=${bar} stuff() } I'm mainly interested in bash, but any info on corner cases in other shells are ...
1
vote
2answers
119 views

Use of find in unix on strange file/directory names

Im a beginner scripter, writing scripts in tcsh and csh (these are taught in my course). I'm writing a script which uses find for putting path of directories this is the part of the script: set list ...
4
votes
3answers
375 views

using sed to replace pattern with hash values

I want to search the file and replace specific pattern with its hash (SHA1) values. For example, let file.txt has the following content: one S56G one two three four five V67X six and I want to ...
4
votes
1answer
66 views

IFS null is not the same as unset IFS?

I read a great question on here called Understanding IFS. I was surprised because the answers and comments quote POSIX which states that IFS= is not the same as unsetting IFS. If you unset IFS, ...
0
votes
4answers
185 views

A shell script that never dies

I want to write a shell script that never dies i.e, Shell script will repeatedly check whether Database is alive or not for every five seconds. The problem is At times the shell script stops ...
0
votes
2answers
74 views

Shell script to find what package provides a file on OpenBSD

# for i in `pkg_info -q`; do pkg_info -L "$i" | grep ^/ | sed "s/^/$i/g" | perl -pe 's/\//\t\//'; done | grep tasklist.desktop xfce4-panel-4.10.0p2 ...
2
votes
3answers
95 views

Syntax error in shell script

I have this script to divide a file over a 100000 or even more in 50000 lines. desc() { echo ...
2
votes
4answers
790 views

How to catch an error in a linux bash script?

I made the following script: # !/bin/bash # OUTPUT-COLORING red='\e[0;31m' green='\e[0;32m' NC='\e[0m' # No Color # FUNCTIONS # directoryExists - Does the directory exist? function directoryExists ...
23
votes
9answers
859 views

for vs find in Bash

When looping through files there are two ways: 1. use a for-loop for f in *; do echo "$f" done 2. use find find * -prune | while read f; do echo "$f" done Assuming these two loops will ...
0
votes
2answers
163 views

how to run .dump command in linux? [closed]

I want to create dump file of sqlite database from java but I can't run the below command from linux. I got the help of windows and I tried with linux but it appears one terminal nothing more than ...
1
vote
1answer
189 views

How can I script xrandr's scale function to switch to the next or previous resolution in a predefined list?

xrandr has a nifty feature that lets you scale your entire screen so that your virtual resolution is larger or smaller than your actual resolution. I use it on my netbook's 1024x600 resolution screen ...
1
vote
1answer
570 views

C shell script : how do I compare two strings?

I'm a C shell user. I've two files. file 1: A B C D E file 2: A C B D E I want to compare only A-A, B-C, C-B, D-D, E-E using a for loop. If the strings match, then print "match". The output ...
4
votes
1answer
118 views

How do I hook into Tar with BASH?

Long Story Short I'm working with Tar archives that contain PNG images in base64 encoding. I would like to use BASH (or whatever else works) to hook into the extraction function of Tar to decode PNG ...
1
vote
1answer
151 views

Delete all jpg in a folder that are smaller than specific width/heigth [duplicate]

I have restored with photorec about 7.500 jpg's. I have moved them all in one folder. A big portion of them is thumbnails. But i can't just go on and delete lets say all of them that are smaller than ...
0
votes
2answers
161 views

Making md5sum understand file names with spaces

I need to use md5sum in Python by using pipe to calculate checksum for a bunch of .mp3 files... is there a command which ignore whitespaces in filenames on the command line of md5sum program? For ...
1
vote
1answer
143 views

while loop is running only once?

I am trying to make a clip out of video file by playing it only for certain interval. make_mclip.sh #!/bin/bash mediafile=$@ mediafile_fullpath=$PWD/./$mediafile tmpedlfile=$(mktemp) mplayer ...
0
votes
5answers
79 views

How can I modify variables

I have the following variable: col=1,3,4, Is there anyway to select the numbers within the variable: (i.e. 1 3 4 and work with them? Such as choosing the "1", "3", or "4" column from a .txt file? ...
0
votes
0answers
25 views

Variable Substitution in sed [duplicate]

I have this script and I need to count the lines inside a file, then pass the number of lines counted to a for loop so that I can get the contents of each line and put it in a variable. My question ...
-1
votes
1answer
92 views

Select a range of files from directory structure /year/month/date.db

I have databases stored in the directory structure year/month/date.db an example would be db/2013/10/15.db I need to be able to select a range of these with a script ("dbSelect ...
3
votes
3answers
268 views

How to put the following information in a CSV file?

I have a text file with the following type of content: OPERATION_CONTEXT VMD1HTE1A71_ns:.oc.GJ_OAD2 alarm_object 1130 On director: VMD1HTE1A71_ns:.temip.VMD1HTE1A71_director AT Fri 18 Oct 2013 ...
1
vote
1answer
123 views

What is the difference between ' and "? [duplicate]

I tried to create a text file in a bash script. The echo command spans multiple lines and has some double quotes "". #!/bin/bash echo "blabla bla bla bla "blabla" bla bla " bla bla bla" and so on ...
3
votes
2answers
158 views

Bash-script. Shift seconds

Maybe somebody can help me. In bash I don't know how to do that. I need to do a bash-script. At stdin I have .srt file of subtitles in this format: num HH:MM:SS,SSS --> HH:MM:SS,SSS text line 1 ...
6
votes
2answers
347 views

Detect if running in a virtual terminal?

I'd like to autologin to tty1 on login and then use vlock to lock it. How can I detect from Bash if the current terminal is a console virtual terminal (e.g. tty1), so that I can put the vlock line ...
1
vote
2answers
121 views

mv complains about standard input in a pipeline that filters file name with grep

I'm trying to move several .avi files that have spaces in from a CD to my home folder. I've already know how to get rid of the spaces: find /media/mathscd/ | grep -L -r "*.avi" | for file in *; do ...
3
votes
3answers
224 views

copying specific files in directory

I am trying to copy some of the files in a directory. The directory contains following files my current directory is ~/certificate/ drwxrwxr-x 2 ubuntu ubuntu 4096 Oct 16 11:58 apache -rw-rw-r-- ...
0
votes
0answers
45 views

When adding a ip via ifcfg how do you have it auto increment the clonenum?

I'm writing a script that adds ips to a multihomed machine. I'm not allowed to use network-scripts folder because well that's what they said. They also stated they wanted to clone num to increase. ...
4
votes
1answer
112 views

returncode of command in a pipline [duplicate]

The following script runs on Solaris using /bin/ksh and on Linux using /bin/sh cmd | tee -a cmd.log | tail exit $? The output of cmd is saved in a file cmd.log and the last lines are displayed on ...
1
vote
1answer
110 views

Binary search for a failing line

git has bisect run to figure out which revision an error was introduced. I have a big file (100GB) and at least one of the lines is bad, but the program I have to check it with will not tell me which ...
2
votes
3answers
109 views

How can i get five seconds of data appended to the end of file?

suppose if a shell script appends a data to a file.txt like 1........... 2........... 3............. 4............. 5.............. Now i want another script that could check the fresh data ...
5
votes
5answers
927 views

Delete First line of a file

How can I delete the first line of a file and keep the changes? I tried this but it erases the whole content of the file. $sed 1d file.txt > file.txt
2
votes
1answer
67 views

Shell Script Size 57M

I have recently Downloaded yEd Graph Editor Installer shell script, which size is 57M When inspect that script head script root@home-pc:/usr/local/src# head yEd-3.11.1_32-bit_setup.sh #!/bin/sh ...
2
votes
2answers
106 views

Awk not rendering any result

My goal is to get the file created in the current month in a directory. It seems that the command is correct but not rendering any result: Date=`date '+%b'` echo $Date Oct ls -l | awk -v d="$Date" ...
2
votes
2answers
157 views

setting variables inside subshell when using <<

I am using the following method in order to pass commands into a subshell that is started by "newgrp". #!/bin/csh echo "Before newgrp" /usr/bin/newgrp users <<EONG echo "hello from within ...
0
votes
2answers
459 views

What is the meaning of $* in a shell script? [duplicate]

In a shell script file i saw "$*", what does it mean and when we have to use it?
1
vote
1answer
218 views

Script to delete text files

I was trying to make a script that searches for all ASCII text files in the directory that you give and after that writes path of every file to a text file. After that it suppose to show head of each ...
3
votes
4answers
507 views

Align text to center with padding on both sides

Is there an easy way to align text to the center with padding on both sides, with the column width being the longest line from the input? For example, this: aaa bbbb c ddddd ee will turn into this ...
2
votes
5answers
146 views

Delete all files in directories except those whose path are listed in a file

Given the following files: data/A/a.txt data/B/b.pdf ... date/P/whatever.log ... data/Z/z.jpg I would like to delete all files in the data/A/, data/B/, ..., data/Z/ directories except those files ...
1
vote
4answers
165 views

Reusing a variable

I was breaking my head for a day still not successful. I have this script: #!/bin/ksh fname=$1 for batchname in $(grep -i "Processing batch" $fname | cut -d "'" -f2) do Batch_state=`grep -c -i ...
1
vote
2answers
294 views

Printing fields using awk

< pool.sam awk ' /./ {printf $1} {printf $7+1,"\t"} {printf $3,"\t"} { if($2 !=16) {print "\t", "+";} else {print "\t","-";} {printf $4,"\t" ,length($10)+$4, "\t", "1"} }' I am ...
0
votes
2answers
68 views

Eval command in unix [closed]

Can someone convert this code? I got this from the web. I am new on this and don't know how eval works. Originally, there is a parameter from a command that is either a plus (+) sign or a minus (-) ...