Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).
0
votes
2answers
32 views
How to check if string contains a substring in dash or ash?
Here is what I am tring:
#!/bin/sh
contains() {
if $(echo $1 | grep -c $2) ; then
echo "0" # contains
else
echo "1" # not contains
fi
}
myString=$1
mySubsting=$2
...
0
votes
0answers
5 views
ZSH mapfile, how can I get the bash behaviour? [duplicate]
Both bash and zsh support reading a file into an array, I'm used to the bash's way and am appalled by the zsh's behaviour: zsh starts the array from index 1! That's not the unix way.
Here is an ...
0
votes
0answers
32 views
Moving files into specific directories based on filetypes
I am having a bit of bother with a control flow statement for a small interactive script I have which sorts and processes unsorted files from a desktop folder.
The script takes in a series of ...
0
votes
2answers
21 views
Getting access to incrementing extension of file (as a integer variable) [duplicate]
I'm trying to code a simple script that uses sed to basic find&replace functionality.
I want to have original file untouched and have results in new files called "file.n" (n is being incremented).
...
-3
votes
0answers
25 views
My site notifice me [on hold]
Can you help me If there any way to notifies me by email when my web site is unresponsive using shell script ?
I try to use manuy script but it dosn't work
2
votes
2answers
95 views
Read file line by line and put in other string
I want to read file line by line and put its content to other string in specific place. I have created the below script but unable to put file content in that string.
File: cat /testing/spamword
spy
...
1
vote
2answers
27 views
Bash can't run command from script: mkdir command not found [on hold]
I have separate scripts for tasks in bash. Here is the broken one:
#!/bin/bash
PATH=/home/name/
mkdir $PATH
cd $PATH && echo "done."
exit 0
Today it broke and first time it simply didn't ...
2
votes
2answers
40 views
list subdirectory with some naming conversion
I want to write a script that will run a certain commands on my subdirectories with names containging or rather end with some strings, say, *-nom1, *-nom2, *-nom3. i.e.
for dir in $(subs)
do
// do ...
0
votes
0answers
19 views
`Unhandled Exception: System.ArgumentNullException: Value cannot be null.` error while running `dotnet run` using a startup script
I'm trying to run a dotnet app using dotnet run --configuration Release at system server Startup/Reboot. I'm using a init.d script to acheive the same.
My startup script, located at /etc/init.d/...
1
vote
1answer
16 views
Shellscript curl gives error
I am trying to create a little shellscript using curl.
This is the script(i need to hide the username,url & Co.)
for i in `cat cain.txt`
do
uuid=$(curl -X POST -H "ACCEPT-LANGUAGE:en" -H "...
0
votes
1answer
17 views
shell for compressing files in batch
I have a server where there are more than 5.4 million files with random nomenclatures. Now I want to write a shell script to compress those files into 1000 gz files of 5400 files in each. I also want ...
2
votes
1answer
23 views
Clean way to bring back background process to foreground in shell script
As an example:
I have working shell script which starts up weblogic (which will continue to run) and then do deployment
At the end I bring background process back to foreground, so that shell script ...
1
vote
2answers
47 views
Sync same directories between two linux servers
There are two RHEL 7.2 linux servers located in different places. Both have same directory structure. Requirement is to keep certain directories of both servers in sync, i.e any modification in ...
1
vote
2answers
55 views
Bash script performance
In a bash script, some integers in a range are generated, concatenated with fixed strings, and printed on a file. OS is Ubuntu 14.04 and bash version is 4.3.11(1)-release.
The strings (and so the ...
-2
votes
0answers
22 views
check validity of input username [on hold]
I want to write a bash script that read an input and then check whether the input
is equal to any users of ubuntu then login else again ask you to enter an input.
function f{
echo"please enter a ...
0
votes
2answers
85 views
Need help with this script which looks up every .c file in the current directory for the strings printf or fprintf [on hold]
Write a script called to look up
0
votes
3answers
37 views
bash: clear string between two positions
I need to clear string in terminal between two positions (not the beginning or end of line). For example, delete all starting from tput cup 5 10 and till tput cup 5 69. One line.
Yes, it's possible ...
0
votes
0answers
5 views
sftp proxy setup to connect to remote server which is not in the same network
I'm new to bee to the unix world, I have to connect to remote server which is not in the same network I'm working. I have the username, ip address and password for the server.
i tried this command to ...
1
vote
1answer
21 views
Sort the directories and files in each directory in ascending order and export data to csv
I have 30 directories i have more than 300 text files in each, all text files in each directory have same naming format
regional_vol_GM1.txt
regional_vol_GM2.txt
regional_vol_GM*.txt
I would like ...
-4
votes
0answers
14 views
How to get and kill the process related to project [on hold]
#!/bin/sh
processName=$1
processKilled=false
OS=`uname`
export OS
case $OS in
Darwin)
processIds=`ps -ec | awk "/$processName/ "'{print $1}'`
;;
*)
processorType=`uname -p`
export ...
47
votes
2answers
4k views
Why is pattern “command || true” useful?
I am currently exploring Debian packages, and I have been reading some code samples. And on every line in, for example, the postinst script is a pattern.
some command || true
another command || true
...
-3
votes
1answer
21 views
I want a script which will delete all the files in the directory except the last days files [on hold]
ex:
files come on 9th and 10th and 11th, we do not know the number of files coming each day. i want to just keep the files of 11th and delete the ones of 9th and 10th
0
votes
1answer
30 views
bash one-liner: set variable to output of command or to default value if output is empty
I know that in Bash you can use the syntax
editor=${new_editor:-/usr/bin/vi}
which will set editor to new_editor if the variable new_editor is not empty and to /usr/bin/vi otherwise. Is it possible ...
0
votes
0answers
31 views
Unmonting a filesystem without crashing kernel
I've mounted a file system 32 bit over fedora 24 64bit. The problem comes when I unmount it. my pc doesn't accept any command and I must give shm permission with chmod 1777 /dev/shm to restart browser ...
0
votes
1answer
29 views
Compare length of string AND if string contains numbers [on hold]
I'm trying to make a shell script where the user inputs a date and then the script is supposed to check to see if the date is in the valid format, mm/dd/yyyy; all numbers. I'm able to use substrings ...
0
votes
2answers
29 views
How to remove the lines that have empty fields?
I have a CSV file with multiple columns, comma "," separated and numbers of lines.
some lines have empty one or two fields "Columns". How i can identify in a separate file and/or remove those line ...
-1
votes
0answers
30 views
for loop or while loop to read the fields of a file
I have two files File_1 and File_2 (reference file). I have to compare the 1st digit of File_1's 2nd column to File_2's 1st column for tagging and count. I also have to sum up the 3rd column of file_1 ...
0
votes
0answers
20 views
gawk fieldwidth to pass as parameter [on hold]
I have questions here from gawk
I have fixed width file which I am trying to conver into Csv comma delimiter.
Unable pass as parameter or variable for fieldwidth options.
Please let me know how to ...
2
votes
0answers
21 views
Reading the status of the screen
I used to read the status of rotation of my screen with this command in fedora 22:
status=$(xrandr --verbose | grep LVDS1 | awk '{print $6}'
and the output would be something like noraml or inverted ...
10
votes
4answers
866 views
How to get last part of http link in Bash?
I have an http link :
http://www.test.com/abc/def/efg/file.jar
and I want to save the last part file.jar to variable, so the output string is "file.jar".
Condition: link can has different length ...
-4
votes
0answers
20 views
Fixed width to delimited file for more than 1000 columns
I have a fixed width file with more than 1000 columns. It needs to be converted to a delimited file along with column header with the delimiter as |(pipe symbol).
Control file of excel type(.xlsx) ...
1
vote
1answer
42 views
How to execute a command inside a shell script without opening a new shell
I would like to execute commands inside a shell script and store in a variable, but it is opening a new shell which I do not want. Is there any way to correct this? Here is my script.
#!/bin/bash
V1=...
1
vote
0answers
18 views
Using a custom filter via script to reject inbound email
Background & Requirements
I've found a number of reference docs and Q&A post relating to this topic but I've not been able to figure out a key area of the design.
I would like to reject an ...
0
votes
1answer
59 views
cleaning output of a script so it's descending, gives package names and cleanly exists
I filed Is there a way to find patches which need testing from packages you have? and I was given a script which works -
for source in $(dpkg-query --show -f '${source:Package}\n' | sort -u); do bts ...
3
votes
2answers
36 views
tailf output as script parameter
Why is it when I leave the following tailf running:
tailf /var/log/z-way-server.log | grep --line-buffered device-info | gawk 'BEGIN { FS = "\"" } ; {print $4,"is",$8}'
I get my desired output:
Den ...
-1
votes
2answers
25 views
Copying files while maintaining file attributes
Say, if I want to copy /etc/bin to a folder while maintaining the file attributes as well as parent directories. [The target folder should not just contain bin folder but /etc/bin.]
Is the possible ...
0
votes
1answer
19 views
Checking if software is installed in SSH session
I am trying to check whether a certain package is installed on remote machine in bash script.
If I execute the following statement on the machine itself the result is 1 (installed) in file check.txt, ...
2
votes
1answer
19 views
How I can find line(s) which the third columns is not digit/date?
I am trying to use awk command to find line(s) which the third columns is not digit/date? Suppose there is a file comma "," field separated, has three columns and as code "," measure "," dd/mm/yyyy,
...
-1
votes
1answer
35 views
Append value as parameter to shell script
I found the value of a response (curl) with sed and now i need some help to take the value that i printed in a file and to use it in another substring in the same .sh script
This is the response of ...
0
votes
2answers
54 views
Extract UUID value from JSON returned from HTTP reply
I am trying to make a little script in shellscript that takes one serviceUuid from a response and use it.
I just print the server response on a file called final.txt
Now i need to extract the value ...
1
vote
2answers
69 views
Syntax error: “(” unexpected (expecting word) — in my bash script
I have a bash script:
#!/bin/bash
VAR1="var1"
VAR2="var2"
VAR3="var3"
cat ${VAR1} \
<(echo -e '<something>') \ # <--------- here's the error
${VAR2}/...
1
vote
1answer
22 views
How to check creation of two new files in bash and perform action?
I have written a script which will check if a single new file is created and perform the action. However I want to perform that action if 'two' new files are created. Below is the script :
old_count=...
1
vote
1answer
26 views
Save temporary history via script
I want to save the temporary history to a file via script. In the bash it works like that:
history -a /tmp/tmp_history
But if I add this line to my script, the tmp_history is empty. I use it like ...
-1
votes
1answer
57 views
How to sort and join files in linux with huge data and print blank values for the values which are not found
Consider the below files :
file1:
1
2
3
4
file2:
2
3
6
9
expected output:
1 NULL
2 2
3 3
4 NULL
NULL 6
NULL 9
I have tried paste file1 file2 | sed 's/\t/\0\t/g' | column -s $'\t' -t ...
0
votes
2answers
32 views
Count the number of processes and send a email to multiple people if it exceeds certain limit
As part of smooth functioning on my application I want to check a count of a particular process and send a email to multiple people if it exceeds certain limit.I have written script for counting ...
1
vote
2answers
27 views
Finding last character of base file name
Say there are different files,
script.sh
text.txt
pic_1.png
or files with no extension - 'hello'.
How can you extract the last character of base file name?
ie,
script. sh - t
text.txt - t
pic_1....
2
votes
2answers
32 views
Applying bash function to each file in subfolder recursively
I am trying to write a script that will apply a bash function for each file in a directory recursively. For example if the directory tests had all my files and sub-directories in it, the script
find ...
0
votes
0answers
13 views
How to create a local apt repository for Hadoop, HBase installation?
I want to create a apt repository for Hadoop and HBase installation, over my private LAN, so that people in my LAN can just to do apt-get install hadoop and install hadoop cluster. There are ways ...
-4
votes
0answers
37 views
while loop issue [closed]
i am using while loop to loop through lines a file and for each line it will start another script.
Example, in list file data is as follows:
NEWYORK
CHICAGO
NEWJERSEY
WASHINGTON
SFO
it has to loop ...
0
votes
0answers
17 views
lock bash script to prevent parallel running from within the script itself?
I am aware of using flock and solo (not sure the difference though) when running from a cron job. However, is it possible to prevent parallel running from within the script itself?