Shell Scripting

10K

Solutions

6K

Contributors

The term 'shell' refers to a general class of text-based command interpreters most often associated with the UNIX and Linux operating systems. Popular shells include Bourne, Debian Almquist (dash), Korn (ksh), Bourne Again (bash) and the C shell family (csh). Some view the DOS 'cmd' prompt as a minimal shell of sorts. It is also possible to install Cygwin on Windows and emulate a full Unix environment with complete shell capabilities. Terminal emulators, such as xterm, GNOME Terminal and OS X Terminal, can be used to access shell.

Dear Experts,

I need 2 files compared on columns 13 and 14 (example: first line of first file > 3405143 5954504 ), and the differences written in seperated files.

If in file1 and not in file2 then write that line to "gone.txt" file.
If in file2 and not in file1 the write that line to "new.txt" file
If in file 1 and in file2 write that line in "stillthere.txt" file

file1
IN0R0300 IN0R0301_P P_IN56CEXP ABORTED 02/21/2020 065000 02/21/2020 070258 LBKL203 SYS_BATCH 000000 100 3405143 5954504 02/21/2020 epk 000 000 00 5407344 Launching Thaler XNINMLT MLTL_F1344914 W6 0000
IN0R0040 IN0R0041_P P_IN56CEXP ABORTED 02/21/2020 090623 02/21/2020 091224 LBKL203 SYS_BATCH 000000 100 3405585 5956805 02/21/2020 epk 000 000 00 5409565 file MBRS_20200221060228494_be07001648317966.edi 0000
IN0R0040 IN0R0041_P P_IN56CEXP ABORTED 02/21/2020 091344 02/21/2020 091458 LBKL203 SYS_BATCH 000000 100 3405615 5956984 02/21/2020 epk 000 000 00 5409747 file MBRS_20200221060234621_be02001352669040.edi 0000
IN0R0040 IN0R0041_P P_IN56CEXP ABORTED 02/21/2020 091714 02/21/2020 092555 LBKL203 SYS_BATCH 000000 100 3405628 5957067 02/21/2020 epk 000 000 00 5409826 file MBRS_20200221060308372_be46001027379136.edi 0000

Open in new window


file2
FT0Y7100 FT0Y7100_P P_FT56CEXP ABORTED 02/21/2020 000002 02/21/2020 000002 LBKL203 SYS_BATCH 000000 100 3399102 5948246 02/21/2020 epk 000 000 00 5401245 chain's name: FT0Y7100 0000
IN0R0300 IN0R0301_P P_IN56CEXP ABORTED 02/21/2020 065000 02/21/2020 070258 LBKL203 SYS_BATCH 000000 100 3405143 5954504 02/21/2020 epk 000 000 00 5407344 Launching Thaler XNINMLT MLTL_F1344914 W6 0000
ZMKTRCOD ZMX0850001 T_TH56CEXP ABORTED 02/21/2020 155227 02/21/2020 155227 LBKL203 SYS_BATCH 000000 100 3406949 5963705 02/21/2020 epk 000 000 00 5416287 chain's name: ZMKTRCOD
IN0R0310 IN0R0311_P P_IN56CEXP ABORTED 02/21/2020 160001 02/21/2020 160246 LBKL203 SYS_BATCH 000000 100 3406974 5963820 02/21/2020 epk 000 000 00 5416396 Launching Thaler XNIN109 IML_F1347154 W2 0000

Open in new window


Many thanks.
W
0
error starting ubuntu vm
ubuntu
i did this before i restartvm
https://help.ubuntu.com/community/Oracle%20Instant%20Client
0
I need help to write shell scripting to generate random number between (0,2147483647) infinite loop, random number will change every run during loop
0
Hi Linux experts,
could you help what is the best way to quickly or fastest way to find files with number range please. Basically need to copy files between 4000 and 5000 range.

Since this directory is huge, so my below command takes very long time to execute :)

for i in My_liferay_{4000..4005}*csv; do echo $i; done

Files
My_liferay_4000_1_51.csv
My_liferay_4001_1_52.csv
My_liferay_4002_1_53.csv
.
.
My_liferay_5000_1_60.csv

Open in new window

0
I need assistance to write shell script to resolve guess number game, called “guess.sh" this shell script will use  guess2  program  which written by C Program to generate a secret number and shell script “guess.sh” will ask user to guess a secret number which generated by guess2 program .
0
Hi,

If I write to a logfile in powershell and open it with cmtrace, it is locked.
How can I avoid this?

J
0
Hi
I have a comma separated values in two variables, would like to compare both variables and get values which are available in both variables.

leftString="ami-06bc7b1fd6d88be49,ami-04db3b64b5f3990dd,ami-0063dd4d697377715,ami-01f8ea3141121cda4,ami-083a15980f7fcf2ad,ami-0b22b5f710211"
rightstring="ami-023d322923f1bb271,ami-0390dfc7d966ce65d,ami-04db3b64b5f3990dd,ami-05f492333c31e3971,ami-066e692403bb98cd3,ami-06bc7b1fd6d88be49,ami-07ebe2d3da06f1831,ami-0a621c6a67fc67a3f,ami-0afa5ade0d61726ef,ami-0b41712d2aef56be1,ami-0f0b1e112bdf5034f"

Open in new window


what we are expecting in the final variable as below..since they are in both.
compareString="ami-06bc7b1fd6d88be49,ami-04db3b64b5f3990dd"

Open in new window


thanks in advance
0
Hi experts.

could you kindly help....how to get current date - 45 days in below format please

Basically would like to go back 45 days

YYYY-MM-DD
0
I am running into issue to determine escape characters from master to remote server over ssh.  I can return desired output on remote server with no issues.  Trying to run similar string on master server to remote server to get same result.

Below example is working fine on remote server and has expected results:

[root@remote_server ~]# echo ${passwd_expire}
Jun 17, 2020
[root@remote_server ~]# echo ${current_date}
Jan 09, 2020
[root@remote_server ~]# echo $(( ($(date --date="$(echo ${passwd_expire})" +%s) - $(date --date="$(echo ${current_date})" +%s) )/(60*60*24) ))
159

Open in new window


I would like to run those remotely and get same output, but I keep running into bash errors and I can't determine which escape character I could be missing or if it's execution process order is incorrect.

server=remote_server


[root@master ~]# echo ${passwd_expire}
Jun 17, 2020
[root@master ~]# echo ${current_date}
Jan 09, 2020
[root@master ~]# ssh -q ${server} "echo $(( ($(date --date="$(echo ${passwd_expire})" +%s) - $(date --date="$(echo ${current_date})" +%s) )/(60*60*24) ))"

Open in new window


Need some advice on how I can run similar string directly on remote server on this master server as well via ssh.
0
Hi Experts,

we have an in ternatinal network.
Do you know a way, how to determine all my DHCP servers in the whole network ?
0
I remotely connect to Linux virtual box from secure shell (ssh).  I have smallest bitbake project.

I type bitbake from shell prompt.  
The output is as follows:
Nothing to do.  Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information.

Bitbake document says default build task will be executed.
build default task is in Base.bbclass file.

How can I be sure this task actually executed?  How do I print something to the screen from this task?
base.bbclass
bblayers.conf
bitbake.conf
layer.conf
0
Hi Bash experts,

Trying to parse multiple xml files in a directory.
Extract an attribute value from available xml files. e.g liferay-version="20.0.1.5"
sort them and get the greatest value from the identified list. e.g "20.0.1.8" and store them in a variable

Was trying using python, but due to restriction on my work server. couldn't install additional packages, so couldn't use python.

Is it possible using sed/awk/bash or any way please.

file1.txt
<?xml version="1.0" encoding="utf-8"?>
<package date-created="26/11/2019" liferay-version="20.0.1.5" patch-version="5.0">
  <description />
  <system />
</package>

Open in new window


file2.txt
<?xml version="1.0" encoding="utf-8"?>
<package date-created="26/11/2019" liferay-version="20.0.1.6" patch-version="6.0">
  <description />
  <system />
</package>

Open in new window



file3.txt
<?xml version="1.0" encoding="utf-8"?>
<package date-created="26/11/2019" liferay-version="20.0.1.7" patch-version="7.0">
  <description />
  <system />
</package>

Open in new window


file4.txt
<?xml version="1.0" encoding="utf-8"?>
<package date-created="26/11/2019" liferay-version="20.0.1.8" patch-version="8.0">
  <description />
  <system />
</package>

Open in new window

0
I am trying to generate a report that will include the total mailbox quota for all my users.  When I use this string in the exchange admin console:Get-MailboxStatistics -server XXXXXX | Sort-Object TotalItemSize -Descending | fl displayname,database*quota,totalitemsize, I don't get the information I need.  A few of my users have larger quota's set for them.  According to the report that gets generated by using that string, it says that their databaseprohibitsendquota is set to 2GB, but the mailbox prohibit send is set to 4.88GB when I check by logging into the exchange admin console.  Is there a parameter that will get me total mailbox quota, not the database quota?
0
Hi bash experts,
would like to convert below log file separated by | into a nice table within my bash script. Is it possible? please help

lifray-portal-dev|464646464efef9||0|sometext
lifray-admin-dev|464646464efef9|ami-987654321|1|sometext
lifray-portal-test|464646464efef9||0|sometext
lifray-admin-test|464646464efef9||0|sometext
lifray-portal-sit1|464646464efef9||0|sometext
lifray-admin-sit1|464646464efef9|ami-987654321|2|sometext
lifray-portal-ppte|464646464efef9||0|sometext
lifray-admin-ppte|464646464efef9||0|sometext


found few links, but looks bit complex
https://www.unix.com/shell-programming-and-scripting/109997-csv-table-one-liner.html?_sm_au_=iqVvmlnQVN3VDHZrBJ3vvK7RJCBJt

https://unix.stackexchange.com/questions/105501/convert-csv-to-html-table?_sm_au_=iqVvmlnQVN3VDHZrBJ3vvK7RJCBJt
0
I know an ex-colleague has a way at command line (script or whatever) to automate
adding of IP to block malicious IP for Nokia Checkpoint : that's years ago.

My current network colleague says it's very tedious to add IP as he has to create
object, then go into another screen to add it to a group & we often get 100-700
IP from threat Intel (from a cyber regulator):  is there a way to automate to mass
block it for CheckPoint  Security Gateway 12600??     Isn't there a way to get to
SG12600's Unix command prompt & write a script to automate?


For sure Linux iptables, we can do it easily by Shell script.

Heard Palo Alto has an interface to add IP en masse but my network guy says
CheckPoint (& possibly Fortigate) don't.
0
Dear Experts,
I reckon you can help me, I'm struggling with assigning a variable in heredoc.
Everything works fine until I want to assign the pid value to a variable...

Script:

#!/bin/bash
set -x

#function
GetLine() {
ssh -T myuserid@"$server" <<EOF
sudo su - "$side""$container"
echo "$side""$container"
pgrep "$side""$container"
pid=$(pgrep "$side""$container")
echo "pid = "$pid""
exit
EOF
}


env=PRD
side=bas
for server in sv-com-bas-p1 sv-com-bas-p2
do
        suffix=$(echo $server | awk -F"-" '{ print $4 }')
        for container in cbs xcf
        do
        :
        GetLine
        done
done

Open in new window




Output:


+ env=PRD
+ side=bas
+ for server in sv-com-bas-p1 sv-com-bas-p2
++ awk -F- '{ print $4 }'
++ echo sv-com-bas-p1
+ suffix=p1
+ for container in cbs xcf
+ :
+ GetLine
+ ssh -T cgk_tam@sv-com-bas-p1
++ pgrep bascbs
bascbs
24426
pid =
+ for container in cbs xcf
+ :
+ GetLine
+ ssh -T cgk_tam@sv-com-bas-p1
++ pgrep basxcf
basxcf
26669
pid =
+ for server in sv-com-bas-p1 sv-com-bas-p2
++ awk -F- '{ print $4 }'
++ echo sv-com-bas-p2
+ suffix=p2
+ for container in cbs xcf
+ :
+ GetLine
+ ssh -T cgk_tam@sv-com-bas-p2
++ pgrep bascbs
bascbs
14642
pid =
+ for container in cbs xcf
+ :
+ GetLine
+ ssh -T cgk_tam@sv-com-bas-p2
++ pgrep basxcf
basxcf
16769
pid =



I know I most probably have to comment the variables in the pid=$(pgrep "$side""$container") line but whatever combination I tried was unsuccesful.
What am I missing?.
Thanks for your help.
0
HI,

I'm trying to modify below python script o produce nice tabular output. (Right now its not in a readable format)

Thanks in advance

Script source:
https://github.com/hjacobs/aws-cost-and-usage-report/blob/master/aws-cost-and-usage-report.py

Current output
./aws-cost-and-usage-report.py
TimePeriod	LinkedAccount	Service                                 	Amount	Unit	Estimated
2019-11-08 	 21212121212121	AWS CloudTrail 	 	 	                       0.153943 	 USD 	 False
2019-11-08 	 21212121212121	AWS Config 	 	 	                          9.213 	 USD 	 False
2019-11-08 	 21212121212121	AWS Direct Connect 	 	 	                   0.2797877163 	 USD 	 False
2019-11-08 	 21212121212121	AWS Key Management Service 	 	 	                   1.4141780112 	 USD 	 False
2019-11-08 	 21212121212121	AWS Lambda 	 	 	                   0.0804225759 	 USD 	 False
2019-11-08 	 21212121212121	Amazon DynamoDB 	 	 	                   0.3836161225 	 USD 	 False
2019-11-08 	 21212121212121	Amazon EC2 Container Registry (ECR) 	 	 	                   0.0783308328 	 USD 	 False
2019-11-08 	 21212121212121	Amazon EC2 Container Service 	 	 	                              0 	 USD 	 False
2019-11-08 	 21212121212121	EC2 - Other 	 	 	                   6.8639388761 	 USD 	 False
2019-11-08 	 21212121212121	Amazon Elastic Compute Cloud - Compute 	 	 	                  73.1890902202 	 USD 

Open in new window

0
I have the following in a php file:

<?php
$output = shell_exec(dirname(__FILE__) . '/add_sku_to_get_flat_rate_quotes.sh');
?>

When I call that file from a browser, it is supposed to run this .sh command in another file in same dir:

me@myserver:~/public_html/mywebsite.com/symfony$ app/console myaccount:get_flat_rate_quotes sku 7017

Which is supposed to add that sku to a table. When I run that sh command from an SSH terminal, it works. What am I missing?

My web host confirmed shell_exec will work on my server.
0
Hi linux experts

Have a huge directory in linux, since many users access and creates files/driectories. even thought we instructed the team...sometime files are owned by them.

As an automation process which reads this parent directory, it fails if its owned by others. automation process can only read and write if its owned by uid/gid 1000
So I run a script on a regular basis as a root to set chown (1000:1000) and chmod 775, so my automation never fails.

Is there a smarter way to handle this situation please. Irrespective of logged user or whoever creates it....files/directory should be set to 1000.

May be g+s set on the parent directory, so all child objects are owned by 1000

please advice/suggest
0
Q1:
Without TCL/Expect script, can someone provide  a Shell/Perl script  or way to automate changing of a couple
of Solaris account passwords every 60 days?  This is for nagios (& a couple other) Solaris accounts which we
have to auto-expire but we can't afford to miss, else the expired password would cause service disruption.
Passwd, usermod or RHEL's chage can't read input from a file, thus I've not been able to find a Shell/Perl
script to do this.  However, we don't want to install TCL/Expect in our Solaris 10.

Q2:
if we use sed or awk to change the 'hashed' password field of /etc/shadow,  would Solaris (or even RHEL)
deem the password has been changed or UNIX will still deem it's not changed yet as we're editing the
shadow/passwd files directly instead of using commands like passwd/usermod/chage to change
0
I have files in unix path
/test1/dev/etl/log

AA_RES_PERSON_20191124.CSV
AA_RES_PERSON_20191124.LOG
KKK_AAA_BB.CSV
AA_RES_TEST1_20191222.CSV

AND SO ON


What i want is find all files with aa_res just for yesterday and then delete it

i want to write it as unix script with number of days to delete as parameter and  /dev path enviorment as variable as code will run in uat and prod
0
Hi Experts,

Could you help me how to find below special charcters "&#141;&#26;&#26;" in JAVA and Shell Script please.

This appers just of the first name of a person. Since we are not identifying this...this slips through our process and fails at the end of complete process. if we could identify this as part of the first parsing step. it would save lot of reprocessing time and defects etc.


This is what I see in a XML file
Firstname &#141;&#26;&#26; Lastname


Same above character in a CSV file after the complete process failed
Firstname � Lastname
0
I performed one of the CIS RHEL 7 hardening remediation.
Got the message with <== shown below, can someone advise:

$ cat  /etc/systemd/system/local-fs.target.wants/tmp.mount
[Mount]
What=tmpfs
Where=/tmp
Type=tmpfs
Options=mode=1777,strictatime,noexec,nodev,nosuid

[root@mesopv1]:/etc/modprobe.d
$ systemctl unmask tmp.mount

[root@mesopv1]:/etc/modprobe.d
$ systemctl enable tmp.mount
Failed to execute operation: Invalid argument <==

[root@mesopv1]:/etc/modprobe.d
$
0
HI Bash/Shell experts,

would like to search for a string "my.example.lab.com" in a parent directory recursively on a xml file type in a single line please

1. Parent directory might have multiple sub directories and sub directories within subdirectory
2. There is a possibility each sub directory might have multiple xml files
3. xml file might contain that string
4. would like to find the xml which has this string and replace with "my.example.test.com"

Also is it possible to execute dry run. e.g just identify the files and not to replace the string pls

thanks in advance
0
hi how can i add user to a group in linux i what to move user from root group to another user
group
0

Shell Scripting

10K

Solutions

6K

Contributors

The term 'shell' refers to a general class of text-based command interpreters most often associated with the UNIX and Linux operating systems. Popular shells include Bourne, Debian Almquist (dash), Korn (ksh), Bourne Again (bash) and the C shell family (csh). Some view the DOS 'cmd' prompt as a minimal shell of sorts. It is also possible to install Cygwin on Windows and emulate a full Unix environment with complete shell capabilities. Terminal emulators, such as xterm, GNOME Terminal and OS X Terminal, can be used to access shell.