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

learn more… | top users | synonyms (2)

1
vote
2answers
36 views

Shell script with directory input

I'm writing a shell script that is supposed to take in one parameter (a directory name) and display how many files, directories, readable files, writable files and executable files are in that ...
1
vote
1answer
11 views

How can I record Shell script outputs to log file

My Shell script include series of steps for example first step App= read -p "### Please enter Application name " Env = read -p "### Enter Enviornment name (Dev,test)" second step cd /opt/...
-1
votes
0answers
18 views

How to use globs in flow control?

The overview is that in traversing directories, I have a file called .txt that is generated from a database dump. I want to run a cron job that goes through and renames the info.txt to ${PWD##*/}.txt,...
0
votes
1answer
23 views

parse a really simple markup grammar with a shell script

I have to parse a file, kind of a config file, that is adopting a really simple grammar : there are 2 kind of multiline blocks and inline markup tags . the block of type 1 is marked by an open_tag ...
0
votes
1answer
40 views

Extract text from a file based on some criteria

I have a file which contains records like those: 434419\Teclu\Tudor\1501\9502 187650\Cosma\Sorin\1504\9253 239474\Teclu\Daniel\1502\5245 844936\Gaman\Mihai\1505\4074 942341\Avram\Tudor\1505\4543 ...
0
votes
2answers
21 views

How to use find with already written script?

I know how to find last modified files, but how do I use it with my already written script. In folder I have hundreds of files xyz_<yyyymm>, now I use $ find /home/directory/TEST/ -type f -mmin -...
0
votes
1answer
30 views

compare two csv files and fetch matching data into a new csv file

I have two csv files with similar content/data. file1.csv ADIS BAP3 Mercury_System nxh-2003 DR_FeatureUP_PT file2.csv ADIS,projects.adis EcoSystems,projects.ecosystems em1xxxsw,projects.em1xxxsw ...
3
votes
3answers
41 views

What situations exist where Bash variables should not be double quoted? [duplicate]

I'm aware of several situations where it's unnecessary to use double quotes when expanding a variable in Bash, such as inside [[...]], or when used on the right hand side of a variable assignment. ...
1
vote
1answer
36 views

Fork Bomb: Why Piping Output Into Another Copy of Fork Bomb works if no Output is returned? [duplicate]

I understand the basic syntax of this famous fork bomb : ( ) { : | : & } ; : but I am currently struggling to understand the part of : | :, where one pipes the output of : to another :. What I do ...
6
votes
1answer
336 views

Meaning of '2> >(command)' Redirection in Bash

A while ago I made a script and I added some logging around it, but I forgot how the redirection for the logging works :-( The gist of it is: #!/bin/bash LOGFILE=/some/path/mylogfile ( # here go ...
1
vote
2answers
27 views

Break out of while loop on error

I have a while loop in this form: while :; do performTask1 || break performTask2 || break performTask3 || break ... performTaskX || break done Basically, I want to break out of the ...
1
vote
1answer
12 views

What does status_of_proc mean by bracket-points-bracket?

In an init.d script using a few /lib/lsb/init-functions, I got this line to report the status. log_daemon_msg "Status" "$APPNAME" ; status_of_proc -p $PIDFILE $DAEMON && exit 0 || exit $? ...
1
vote
2answers
36 views

Extracting string up to first digit in Bash

I would like to find a straightforward method to extract the portion of a string up to where the first digit appears (possibly using regular expressions instead of traversing the string character by ...
0
votes
3answers
43 views

Integer expression expected in if statement

I have a small shutdown script, if the Mac runs over 24 hours it will shutdown. I'm not really experienced in bash scripts, but I did this: !/bin/bash #Maximum number of days to be up max=1 #Get ...
0
votes
0answers
29 views

Why my script is not terminating after I exit the shell? [duplicate]

As far as I know if we are using & after a command or script, it will exit once the shell is terminated or logged out. So I have a simple infinite loop script and I am executing it like :: [root@...
3
votes
1answer
15 views

shell variable value in for loop different after loop

I have a challenge with a variable value changed in a for loop and the value of that variable after the for loop and using tee SCRIPT_1: STATUS=9 for SESSION in A B C do ...
0
votes
1answer
27 views

Why does this echo call overwrite existing text?

Consider the following CSV file: jdbc.driverClassName,oracle.jdbc.driver.OracleDriver jdbc.username,kshitiz It has to be transformed into: -Djdbc.driverClassName=oracle.jdbc.driver....
0
votes
2answers
31 views

How to reformat the directories names?

I have many directories with the names as following geom1 geom10 geom11 geom12 geom13 geom14 geom15 geom16 geom17 geom18 geom19 geom2 geom20 geom3 geom4 geom5 geom6 geom7 geom8 geom9 I would like to ...
1
vote
1answer
26 views

How to use inotifywait to watch a directory for creation of files of a specific extension

I have seen this answer. You should consider using inotifywait, as an example: inotifywait -m /path -e create -e moved_to | while read path action file; do echo "The file '$file' ...
0
votes
1answer
35 views

Terminology for Command in Command $( … )

I have a script update-wallpaper that goes somewhat this: ln -s $(get-wallpaper-path) ~/.config/bg-manager/wallpaper The experssion $( ... ) is called... something... and searching the symbols $() ...
2
votes
2answers
18 views

Read columns from file, then column into an exsisting csv file

Essentially, I have a csv file that contain multiple columns, called cols.csv 1,a,100 2,b,200 3,c,300 4,e,400 and I have a new csv file that has one column, called col.csv f g h i I want to copy ...
2
votes
2answers
45 views

A script that is executed fine from file breaks when executed with Heredoc

I can run the following script just fine using the traditional way of: cd ~ && vi script.sh [PASTE SCRIPT INSIDE] && chmod +x script.sh && ./script.sh && rm -rf script....
0
votes
2answers
32 views

Trying to figure out Linux script

I am a fairly new Linux user and I am trying to put a script together for a class. The script is supposed to allow a user to type in a username, and it will say if the username exists or not. If it ...
2
votes
1answer
52 views

Script for network restart

Sometimes network completely fails on my server for samba shares (e.g. I could'n connect to server via ssh and samba shares were unavailable). Since there is no working solution to fix it (full ...
0
votes
0answers
43 views

Identify whether user is able to login with the given user ID and password

We have 300+ AIX servers.We have created local id for a user on all those servers.Now the user has to log in manually in all servers to check his whether credentials are working.So is there a way/...
1
vote
4answers
62 views

How to check if a variable entered is alphanumeric or not in ksh?

I am using ksh on AIX and I want to check if a variable, for example var1=sanySAN, var2=SANYsa%$3 is alphanumeric or not. Here, var1 is alphanumeric and var2 is not. I know I can use [a-z][A-Z][0-9] ...
2
votes
2answers
79 views

How to convert row to column

Please help me to convert the row values into column.  My input file.dat is: First two fields are alpha string and numbers respectively and input will always have same number of fields i.e., 6. ...
0
votes
0answers
32 views

Can't set chown from bash script [on hold]

I have a bash script like this one: #!/bin/sh chown root:www-data /etc/cron.d/file chown root:www-data /etc/cron.d/anotherfile But chown command isn't working. I know it's because of file ...
0
votes
2answers
23 views

Loop until grep does not find the text in a file

I have a file named file.txt. The content of the file is as follows sunday monday tuesday I wrote the below script and it loops just fine if the grep cannot find the pattern that was mentioned ...
4
votes
4answers
251 views

concatenate lines based on first char of next line

I am looking for away contact lines based on the next line. So far the only way I see is to create a shell script that will read line by line and will do something along these lines: while read line ...
0
votes
2answers
26 views

How to convert seconds to hh:mm:ss format from output of another shell script

everyone here is my script /bin/wstalist | grep 'uptime' Which is return value like "uptime": 3456, yes there's a , coming with output. These number are seconds. I want to convert it to hh:mm:ss ...
0
votes
0answers
7 views

how to copy file form one server to another server which are created within 2 minutes [on hold]

i am beginner in shell script so please help me how to copy file form server which are create with in two minutes and i want to use corn job run every 2 minutes copy those file which are create with ...
0
votes
1answer
53 views

Command works when copied and pasted but not in a bash script?

I'm trying to pass a windows command into a linux netcat shell and then read back the output. So far I have: cat <( printf 'ipconfig\n' )| nc -v 137.148.70.243 443 Which when copied and pasted ...
1
vote
2answers
40 views

Can “at” command execute any kind of shell script?

I created a java program that showed a message dialog. After pressing OK it is closed and the program execution ends. Then I created a shell script alarm.sh that executed the program. I tested it and ...
3
votes
3answers
91 views

Checking a script is running [duplicate]

I have a job test.sh schedule to run every 5 mins, and another job test1.sh scheduled to run 12.30pm , @12.30 both jobs will run and is making a deadlock. So I need to check the job test.sh is running ...
2
votes
2answers
26 views

Multiple commands with quotations after SSHing

I have a server I have to ssh into with many commands which feature the use of variable assignment and consequently a lot of quotation marks. If we consider the script: ssh user@host "kinit -k -t /...
0
votes
0answers
27 views

Get the multiple filename in linux [on hold]

I have filename like, filename1.ZIP.zip, filename2.ZIP.zip, filename3.ZIP.zip After double extracting I'm getting some filenames, that filename I want to read or store into variable. How to do? ...
-8
votes
0answers
47 views

How to get the every first file in a multiple folders copy into a single folder? [on hold]

I have a 250 sub-folders. How do I get the every first file in multiple folders copied into a single folder?
0
votes
1answer
12 views

Create a action in Sylpheed to decrypt messages

If you like to decrypt messages in the Sylpheed email client the manual suggest to create a custom action to execute the following command: *gpg2 --no-tty --batch --yes --command-fd 0 --passphrase-fd ...
0
votes
1answer
38 views

Writing the output of a command to a file in a bash script

I am trying to write a simple bash script that executes the command tcprobe -i $1 where $1 is an mp4 file. Then, I want to write the output of this command, which should be a long string of ...
1
vote
1answer
34 views

Check the count of records from the source file and the loaded target

I have some source file suppose mydata.csv and my target table.I want to validate the record count whether it's same between the source file and the target table .The target table is in hive. I have ...
3
votes
2answers
101 views

Store netcat output into variable

I want to store the output from an netcat function into a variable. I tried a lot of different ways, but it doesn't work to me. Can someone help me? The whole scripting thing is whole new for me! #! ...
1
vote
2answers
54 views

Is it possible to write to the crontab from a multipurpose script?

When I want to manipulate Unix cron I do $ crontab -e And then type (or paste) my directives. You might now a way to paste directives to crontab -e directly from a script? In other words: Instead ...
4
votes
1answer
44 views

How can a shell script avoid the SIGPIPE that would be caused by use of closed file descriptor?

A shell script can lose its standard and other file descriptors if the other end goes away. One way this can happen is by terminating a ssh client used to launch the script: $ ssh localhost test ^C ...
0
votes
1answer
38 views

Sound indicator for when a script temporarily stops? For example, to fill in data or passwords? [duplicate]

I have a quite long Bash script I use to install Apache server environments including PHPmyadmin and several other utilities, after logging to the remote machine via SSH. I run the script via the ...
1
vote
1answer
35 views

Audio files altered by a bash command renaming them

Today I submit a case of an unexpected consequence of a shell command on some audio files that I do not understand at all. Here are the facts: My OS is ArchLinux, the windows manager is Awesome and ...
-3
votes
2answers
60 views

How to write bash script to open vi and edit document?

I'd like to write a bash script that essentially automates this process: vi filename.pdf (open "filename.pdf" using vi) :4,7d (in vi command mode, delete lines 4-7) O (in vi command mode, tap ...
-3
votes
0answers
20 views

how to reset user password my multiple unix or linux server. using shell scripts [closed]

here is the problem :- how can reset user password of my rehal 7 solries 10, 11 also i have to use to exception handling. how to log in the server. in staring for checking username is exist or not. ...
2
votes
1answer
43 views

Shell script is not working via cron job

I'm using a script which is working in Stand alone and is not working through the cron job . qexma1@test:bin> head -n 10 test.sh #!/bin/bash declare -r PATH='/sbin:/bin:/usr/sbin:/usr/bin' source $...
0
votes
2answers
50 views

Need to parse a csv file and it should store in variable

I need to parse a csv file and store the value in a variable. Below is the sample csv file And below is the ./script.sh #!/bin/bash D=""; P=""; ./xyz --project "$P" --displayname "$D" For ...