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

learn more… | top users | synonyms (2)

2
votes
1answer
86 views

Leap seconds and date

I've just discovered that Unix time does not include the leap seconds. I think it's quite surprising because doing that, it is slowly diverging from UTC... but that's not the point of my question. ...
0
votes
4answers
245 views

keep the last file of every month and delete the rest

I have files like below. I want to keep SEP 30, OCT 30....files and delete the rest. Can you please help me with any script? -rw-r--r-- 1 nbswmcm advboprd 13463761 Sep 2 01:19 ...
0
votes
1answer
30 views

Loop in script on remote server doesn't work

#!bin/bash client=`cat temp.txt` ssh node2@192.168.1.190 'while read line; do mkdir -p /tmp/$line ; done <<< "$client"' cat temp.txt has 2 lines: nk124 nk124 Above is my script, it does ...
0
votes
1answer
49 views

Shell string escape for command arguments [duplicate]

I'm trying to create "/tmp/pwet/foo bar" with this: DIR="/tmp/pwet/foo bar" ARGS="-p ${DIR}" mkdir $ARGS For integration reasons, I have to keep the ARGS building in 2 steps: ARG = some_options + ...
1
vote
2answers
64 views

React to incoming files in a directory on HP-UX

How can I achieve this logic using a script: Monitor new incoming files in a directory. If files are not received in the directory for 3 hours or if the received file is empty then do something. ...
1
vote
5answers
64 views

Regular Expression for Mixed cased words

I want a regular expression that will help me identify if a certain pattern is present as a mixed case in a sentence or not. Say: Fox juMPed the rock Now, I want to find that if the pattern ...
5
votes
2answers
306 views

delete a line if same line exists in the previous line

I want to remove lines which exist already in the previous line from the command line in UNIX. I have the following data in a file. <xref ...
2
votes
6answers
88 views

Getting the matched word exactly

I have looked through a number of question but they do not satisfactorily reply to my question. I need to print words that match the pattern exactly not the lines containing that word. For example: ...
1
vote
2answers
58 views

Add certain words to a file

I am using this code to read the line number 2 from files has the same name and included in folders (the name of those folders included in list.txt): #!/bin/bash in=/au/cl/tr/129/ inlist=/1/2/3 ...
-1
votes
2answers
69 views

reading from file using the command sed

I have a list of folders (the name of those folders mentioned in the file list.txt).I wanted to read the line 2 in all the files (the files in the folders has the same name) and print that line in a ...
2
votes
1answer
67 views

grep of a shell variable finds nothing

I have some problem with grep. I wrote a script which need to find some numbers from a list (file name ContigsNames) in a database. I wrote the following script: file=ContigsNames while IFS=' ' read ...
1
vote
0answers
40 views

Cannot add startup service to openWRT from init.d

I have openWrt installed on a TP-Link TL-WA901N/ND v3. I don't have luci package installed because I don't have enough space, so I can only do thing via cli. What I'm trying to achieve is to create a ...
1
vote
1answer
31 views

Cron Job Not working [closed]

I have been trying to create a cron job to execute a script located in ~/Documents/script.sh at midnight every night and every 8 hours after that. I have found a lot of material on this but for some ...
2
votes
3answers
61 views

Error while assigning current directory to a variable

#!/usr/bin/env bash if [ "$outDir" == "" ] then echo "$PWD" ,"We are here ", $outDir ," with " "$outDir" = "$PWD" echo "Yes" fi Output on terminal: ...
2
votes
2answers
88 views

How to capture the port number from this `lsof -F` output using awk (or something better)?

I've got output coming from lsof -F that looks like this: p7646 g7646 R8300 csocat u1000 Labe f3 au l tIPv4 G0x80002;0x0 d640391 o0t0 PTCP n*:51352 TST=LISTEN TQR=0 TQS=0 I am trying to capture the ...
2
votes
4answers
72 views

Merging Two Files with Difference only

I have two files. file1 contains text as follows: #This Data written by the platform Team id=kingDB file2 contains the text as follows: #This Data written by the platform Team id=kiteDB,mangoDB ...
1
vote
3answers
38 views

WMCTRL not working after starting xfce4-terminal

If I type these two commands in a terminal: xfce4-terminal --hide-menubar --hide-borders --hide-toolbars --title=dt wmctrl -r dt -e 0,10,10,720,720 I get the desired result (position and resize of ...
0
votes
1answer
44 views

Launch BASH script by clicking icon and preserve terminal icon

My problem is pretty simple, but I must admit, I don't know any elegant solution. I have a problem, that I often accidentally click different icon that I wanted. It's really very unpleasant, so I've ...
2
votes
1answer
45 views

How to run a program that has its own command line within a shell script program

I need to write a shell script to automatically run a set of files through an existing program ~1000 times. The program I'm trying to run them through is accessed through command line as follows, then ...
4
votes
3answers
302 views

Hide ouput of bash while running automated script.

I have a couple of scripts in my bash file, that should do certain tasks, say like ... #!bin/bash yum -y update service restart nginx yum install atop cat /var/log/somelog.log > ...
3
votes
7answers
199 views

get parts of string using shell script

I have one string as /ip/192.168.0.1/port/8080/ I want to get two separate variables which will contain port and IP like. 192.168.0.1 and 8080 as I know /ip/ and /port/ will be there always I ...
4
votes
4answers
358 views

Text files containing their own name

I need to find in certain directory and all its' subdirectories all text files that contain their own name. How do I do this? (preferably without awk command)
2
votes
1answer
28 views

Help me understand what sort is doing here

This is a followup to this question : What does sort -n do with non numeric values? Here is my input: 1-----*** R----**** 1---***** And I run: sort -k 1.2,1.9n input.txt > output.txt Here is ...
4
votes
3answers
110 views

Add text with echo but start with new line if file not empty

I'm trying to create next script echo "#!/bin/sh" >/script echo "del x.txt" >>/script witch is ok if /script file is empty, if not - will append first line to last text #!/bin/sh del ...
0
votes
0answers
24 views

What does sort -n do with non numeric values? [duplicate]

I'm translating an old korne shell script that uses sort. The exact command is: sort -k 1.2,1.9n -k 1.10 -k 1.18,1.19 $LOAD_FILE > $SORTED_FILE The input file has some lines where the values in ...
0
votes
0answers
21 views

Script GUI problem

I have an application in C++ which show a ipcamera video when I send it a value by ethernet. I want that the application start at boot in automatic way. This is my script: #!/bin/sh ...
3
votes
3answers
105 views

Count nul delimited items in file

I have a shell script which uses find -print0 to save a list of files to be processed into a temporary file. As part of the logging I'd like to output the number of files found, and so I need a way ...
-1
votes
1answer
35 views

I get "syntax error near unexpected token 'else' for the following script [closed]

if ! [ $result1 -eq $SUCCESS ]; then # failed to get the status from 1st ssd try with the 2nd ssd, to identify the primary and secondary ...
1
vote
0answers
41 views

Need a script to send an email when an input has not changed for more that 30 minutes

I need a linux scrip that will send an sms when there is an input change and it has not gone to the initial state after 30 minutes, I have the following so far, but, I am sure there are few things ...
3
votes
3answers
181 views

Split the lines of a text file into separate files

I have a text file that looks something like this: foo bar zip rar tar I need to use a bash script on OSX to make a new text file after every new line like this: cat text1.txt foo cat text2.txt ...
1
vote
0answers
18 views

Command is not found [duplicate]

I have this code #!/bin/bash read num sum=0 i=1 while [$i -le $num]; do let sum=$sum+1 let i=$i+1 done echo $sum I am getting the error ./test: line 5: [1: command not found , but I am not ...
5
votes
2answers
388 views

How to treat strings with spaces as a whole in bash? [duplicate]

I'd like to build an error handler which will make an empty file marked with the error_occur time. The core idea is to use the result of date command as a parameter. I did: time_stamp=$(date) touch ...
0
votes
1answer
62 views

Grep -m 1 doesn't work

I'm using the following command to parse a form element from HTML using grep. The $RESP variable contains the output from a previous curl request ... echo $RESP | grep -m 1 -o -E 'name="id" ...
1
vote
0answers
55 views

Udev running hibernation script

I have this udev rule that launches a script when the battery level is 5% or below: $ cat /etc/udev/rules.d/90-lowbat.rules: SUBSYSTEM=="power_supply", ATTR{status}=="Discharging", ...
1
vote
4answers
37 views

How to do grep even if the file is not present?

I am doing something like this in my code file_nm=`ls -latr *abc*` if [ `grep "search_txt" "$file_nm" | wc -l` -gt 0 ] then echo "string found" else echo "string not found" fi If the file_nm is ...
2
votes
0answers
73 views

Write the same file multiple times to one file using dd

I am trying to create large dummy files on a drive using dd. I am currently doing this: #!/bin/bash writeFile(){ #$1 - destination directory/filename, $2 - source filepath $3 - blocksize, $4 - ...
4
votes
1answer
65 views

How to make sure only one instance accessing the file at a time in a folder?

I have a shell script which will be executed by multiple instances and if an instance accessing a file and doing some operation how can I make sure other instances are not accessing the same file and ...
1
vote
1answer
68 views

How to grep the logs for a list of patterns and make a report out of it?

I have a C++ executable which scan some of my files and those files has some user id in it. After scanning is completed it generates below log file (abc.log) like this - INFO [0x7faff2b32a00] ...
3
votes
1answer
63 views

Echo out lines of script before running them

Is there a way to run scripts in bash that makes it so that it prints each line of the script before executing it? This would be really useful to me for debugging... $./myscript.sh echo "Hello" ...
0
votes
3answers
63 views

Pipe/redirect a group of commands

I currently use the following setup to redirect the output of multiple commands: echo "Some normal commands" ( echo "Error: something happened" echo "Warning: this incident will be logged" ) >> ...
1
vote
1answer
74 views

Process Files to create a new file

I have a file1 which contains comma separated values (timein/timeout in military time format eg 0800, 0900, 1300). For each line of File 1 contains timein/timeout for each day. Sample File 1: Name, ...
3
votes
2answers
110 views

How to read needle part of the sed command from a file?

I want to replace a long part of a file with something else preferably by sed but want to read that long part from a file. I already found this: sed -e '/<TEXT1>/{r File1' -e 'd}' File2 from ...
1
vote
2answers
58 views

Extract and format data with `cut` and `awk`

I have the below file in txt: "Firstname","Lastname","Company" "Alex","Johnson","Alex Corp." "Baran","Atasoy","Gülerler Ltd." I would like to extract and format data by using awk and/or cut and ...
5
votes
1answer
92 views

Provide two arguments to one option using getopts

In below code when I give option r then getopts requires one arguments: while getopts ":hr::l:" opt; do case $opt in r ) echo "Run Numbers - argument = $OPTARG " ;; l ) echo ...
3
votes
3answers
118 views

Dash equivalent of self-redirection of script output

In Bash you can redirect all future stdout output of the currently running script. For example with this script, exec > >(logger -t my-awesome-script) echo 1 echo 2 echo 3 This will end up in ...
2
votes
5answers
256 views

Stripping directory paths to get file names

What I am doing is converting mp3's with LAME. I already have an old script I wrote that works but I want to add to it this ability--to no longer delete the file but instead save it in a new root ...
0
votes
1answer
74 views

Back-up script via bash — issues with file paths?

I'm trying to run a back-up bash script in via Plesk scheduled tasks on a CentOS GoDaddy Managed Dedicated Server. I'm having a frustrating amount of trouble with this (made worse by the fact that it ...
1
vote
1answer
41 views

Using find -exec and having trouble with redirecting standard error

I have an individual.sh script that pipes standard error to a grep command, like this: FOUND=$(tesseract "$i" out -psm 0 |& grep -ci 'Orientation in degrees: [^0]') If I run the script like ...
2
votes
1answer
42 views

Move thousands of jpg files into daily directories based on the files EXIF creation date

I have thousands of jpg's and mp4's that need sorting into a directory structure which name is based on the date the picture was created. Preferably from the EXIF date as the files modified date might ...
3
votes
5answers
71 views

search a command in PATH with the same name of the script

For example, my script is $HOME/bin/sudo. I'd like to search for an executable in $PATH with the same name, sudo, and run it - but not the script $HOME/bin/sudo itself, otherwise I will run into an ...