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.

Share tech news, updates, or what's on your mind.

Sign up to Post

This is using a SuSE Enterprise Linux 11 with SP4. A bash shell script was used to do the backup (zipped) from /mm/data1/sqmdat to /mm/data1/Backup. /mm is a cifs mounting of //mmcentral/mm. Please see the attached script. This shell script was scheduled to run as a cron job at 4:30 am daily.

The problem is, we getting a series of "MM Remove Error: DMPxx (CODE: 1)" everyday. If I were interpret correctly, this script is do a check on files for past 65 days, and will "list" those files and then do a "zipping". After that, these zipped files were "moved" to /mm/data1/Backup folder. The last step is, to do the removing. However, it seems that problem happened here, and eventually a mail was sent with "MM Remove error".

Appreciate for the helps.
bck.mmTEST.sh
0
OWASP: Forgery and Phishing
LVL 13
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

Hi  

I need some assistance if writing a script that will produce a log file and send an e-mail notification if a CRON job fails to start
0
Hello All,

I have enabled a Incident report on Transport Rules in Exchange 2016. It sends a below information to specific mailbox.

I would like to get this as report in Csv format. where the below mentioned headings as colums. Is it possible?

I already tried the Search-Mailbox -logonly option, but it does not show the below information in csv.


Report Id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 This email was automatically generated by the Generate Incident Report action.
 Message Id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 Sender: xxxxxxxxxxxxxxxxxx
 Subject : ABC
 To: xyz@abc.com
 Severity: High
 Override: No
 False Positive: No
 Data Classification: Credit Card Number, Count: 1, Unique Count: 1, Confidence: 80, Recommended Minimum Confidence: 85, Location: CCD.txt
 Rule Hit: Sensitive information, Action: AuditSeverityLevel, RejectMessage, GenerateIncidentReport

 Location: CCD.txt
 ID Match: Credit Card Number, Value: xxxxxxxxxxxxx,
 Context: Credit Card xxxxxxxxxxxxxxx

Thanks
Krish
0
Team,

I am trying to create a script for listing emails count which are blocked by Transport Rules. I have totally three transport rules in place, 1. Block credit card and SSN, 2. Block Driver License, 3. Block Driver License in attachments.  The whole purpose of this script is to categorize emails count based on transport rules, so that we can see how many hits for Credit card, SSN and Driver license. I have searched couple of articles but that doesn't give me the exact results what i was looking for.

Do i need to put condition based on Message body (for ex..  Messagebody contains "credit card" and Eventid contains "Fail" or "DSN"?) or Based on Transport rules Name.

It would be a great help if someone can help me with this,


Thanks
Krish
1
Hello,  I have a perl script that I need it to look into a directory named mpl.  right now I run it but it does it for one file at a time. Sucks cause There are a few hundred. So If I can seek hellp to make my perl script open a whole directory and do what it does per one file but in a whole directory.

I need my script adjusted  to look into my directory mpl and read all the zonefiles and change the serial number using date with an extra number 2019011300 ; serial for example

I run the script like this on the below:

./zonechanges.pl db.apptoapp.net.new vipchange

Copy of the script:

#!/usr/bin/perl

open(ZONE,  $ARGV[0]) || die "Zone file error $!";
while ( $line = <ZONE> ) {
        chomp $line;
        push @fileLines, $line;
}
close ZONE;



# Assuming simple CSV of old_ip, new_ip
open(IPMAP, $ARGV[1]) || die "IP Map file error: $!";
while ( $line = <IPMAP> ) {
        chomp $line;
        ($old, $new) = split(/,/, $line);
        $old =~ s/\s+//;
        $new =~ s/\s+//;
        $ip{$old} = $new;
}
close IPMAP;


## For every line
for ($count=0; $count < @fileLines; $count++) {
#       print STDERR "OUTER FOR ($count)\n";
        $line = $fileLines[$count];
#       print STDERR "OUTER FOR have line $line\n";
        ## For every old address in the remap
        for $old (keys(%ip)) {
                #print STDERR "INNER FOR ($old)\n";
                ## If the line matches the old address
                if ( $line =~ /$old/ ) {
                       

Open in new window

0
I previously asked the following question but need additionaly functionality:

I need to modify alot of java files so that each method prints a logging message so hopefully sed will do the trick for me.

Here's an example of the file change.

public void someMethod(int x) {
     System.out.println("xx"); // Sed command should add this line to the java file for every method in the file

Open in new window


And the following sed commands works:

$ sed 's/\(.*public.*(.*{\)/\1\n     System.out.println("xx")\;/;'  ./file.java

Open in new window


But, there's a special case where there might be a
super();

Open in new window

call right after the method declaration:

public void someConstructor() {
    //  Code comment
    super();
    System.out.println ("xx");

Open in new window


Is there logic I can add to the sed statement to skip the super call and add System.out.println statement after the super call?   If System.out.println is added to the method before the super call, the file won't compile.
0
Hello Team,

I am trying to setup a weekly reporting for the below. Can someone please help me in getting the below items in one script?
Its for Exchange 2016 environment.

Top Mailboxes by size
Top Senders by quantity - Would like to list top 10 senders by quantity. Sender Name and Quantity
Top Receivers by quantity - Would like to list top 10 receivers by quantity. Receiver Name and Quantity
SPAM statistics
Total Mail statistics

Thanks
Krish
1
Hello Fellas.
I need your help with something that has been messing with my head for a while.

I have a CSV file filled 3 columns (Full name, user name and organization)

I also have a google-authenticator token generator server running on  Centos 7.6

if I run the command
su user1 -c 'google-authenticator --time-based --disallow-reuse --force --minimal-window --no-rate-limit'

Open in new window



I'll get a response like this from the server:

Warning: pasting the following URL into your browser exposes the OTP secret to Google:
  https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/user1@googleauth%3Fsecret%3D****%26issuer%3Dgoogleauth
Your new secret key is: *****
Your verification code is 529499
Your emergency scratch codes are:
  **
  **

(I obviously redacted the personal parts)

What I need is a bash script, the reads the csv file, the sends the username (2nd col) to the su command then adds the https link and the secret key as new columns.
(I don't mind of it creates a new file or adds them to the existing one)
0
Hello Guys,

I need a script for the following.

Export distribution groups and group members in csv. The objects should have DisplayName, Name, Alias, Emailaddress, members, Managed by

Export contacts as a csv file.

Export  user Mailboxes, Shared Mailboxes, Conf rooms and users who have access to the mailboxes(Full access , Send As access, Send on Behalf).

I would appreciate , if you can provide the script instead of Links.

Thanks
Krish
1
Team,

I need a help on creating bat file script for outlook profile creation. I will be using GPO to deploy the script along all the workstations/ laptops connected to the domain, so that user don't need to manually configure the outlook. Also can some one also suggest me if its possible to include outlook rules in the script?

Also please note that this is for a Mac.

Can anyone please let me know the procedure, how to accomplish this?

Thanks
Krish
0
Introduction to Web Design
LVL 13
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

I trying to familiarize myself with Powershell PnPOnline in particular

Get-PnPListItem -List Requests -Fields "Title", "GUID","RequestStatus","RequestStatusName"

Open in new window


I am running this script and it is getting results but it only showing the same 3 fields (ID, Title, GUID), no matter what other fields include in the parameters.

Any idea if I am doing something wrong? with the syntax?
0
I need someone who understands shell scripting in a PostgresSQL environment to look at this.
I am trying to get the Pgbackrest  (ver. 2.10) application to provide notifications by Email when it encounters errors.
The error reports (either from a logfile or the command pgbackrest info) should be included in the notification.
The email are to be sent from a RHEL server.
CRON tasks currently used sends empty notification emails even when there are no errors.
0
Hello Team,

I am trying to setup a automated Lync creation script with event alert.

It successfully enable the lync account, however i need assistance on creating event for each lync account creation.

Can you please help on this?

Thanks
Krish
0
Hello,

This is a Shell Script to summerize the output of errpt command in Unix AIX but something wrong :

example.sh :

!/bin/ksh
errpt | awk '{print $1}' | sort | uniq -c | \
        grep -v IDENT > err_.junk
printf "Error \t# \tDescription: Cause (Solution)\n\n"
foreach f (`cat err_.junk | awk '{print $2}'`)
set count = `grep $f err_.junk | awk '{print $1}'`
set desc = `grep $f errs.txt | awk -F '{print $2}'`
set cause = `grep $f errs.txt | awk -F '{print $3}'`
set solve = `grep $f errs.txt | awk -F '{print $4}'`
printf "%s\t%s\t%s: %s (%s)\n" $f $count \
                               "$desc" "$cause" "$solve"
end
rm -f err_.junk


Here is the output error :

./example.sh[5]: 0403-057 Syntax error at line 5 : `(' is not expected.

Thanks for any help
0
I have a bash shell script that I want to call a Oracle DB stored procedure with (procedure is in a package with public interface), I am running it on Cygwin:

#!/bin/bash

if [[ $1 = '' ]]; then

  echo
  echo "usage : copy_client_div.sh <master conect string> "
  exit 0
fi

test_db1=`$ORACLE_HOME/bin/sqlplus -s $1 << EOF
set heading off
set pages 0
set feedback off
select 999 from dual;

EOF`

test_db=`echo $test_db1`
echo test_db: ${test_db::-1}
echo ${test_db}


if [[ ${test_db::-1} != 999 ]]; then

  echo "Can NOT connect to database with the given connect string"
  echo
  exit 0

fi

CONNECT_STRING=$1

`$ORACLE_HOME/bin/sqlplus -s $CONNECT_STRING << EOF > /c/temp2/log.txt

set heading off
set pages 0
set feedback off

begin
      --GRANT EXECUTE ON COPY_STUDIES.ins_trial2 TO tsm10;
      execute PackageName.procedure_name(name=>'trialname',client_div_source=>'source1',client_div_target=>'target1',ftuser=>'user1');
      commit;
      exit;
end;
EOF
`

If I run the procedure by itself in a sql script, it works.  In the bash script, nothing happens and no error gets returned.  Can someone tell me what I am missing?  Thanks.
0
Hello All,

I would like to get the list of all the public folders and the size. I got the below cmdlet, however i was unable to get the size of PF.

I just want identity, User, AccessRights and Size.

Get-PublicFolder -Recurse | Get-PublicFolderClientPermission | Select Identity,User,{$_.AccessRights} | Export-CSV "C:\PFPermissions.csv"

Can anyone please help me.

THanks
Krish
0
Hello,

i started new for python, i would like know the equivalent python code for below shell script.

#!/bin/bash
data=?fields=attachment
while read n
do
        curl -u admin:admin@123 -X GET https://jira-dev.abc.com/rest/api/2/issue/$n$data | /usr/bin/jq '.id' >> isad.csv

done < filename

where filename contains
SEC-1
SEC-2
SEC-3

regards
Lingesh
0
This is a php script, which basically does the send mail function via terminal shell, I am studying it and the curious thing is that it worked in my tests only in the Ubuntu 14.04 versions with php5 and postfix. But I could not get it to work on Ubuntu 18.04 or Debian 9. I would like to ask for help to change the code in order to make it work in those versions. Thank you.

javali.php
1
Hi,

Need a unix script to loop through thousands of folders and write a file listing the folders that contain less than x amount of subfolders.

Thank you.
0
Learn SQL Server Core 2016
LVL 13
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Need a python script to copy yesterday files to a destination location and gzip them in destination directory
0
need an archival script that runs on a nighty basis

we maintain our logs for a given month in a directory

/a/b/c/2018-01/xyz-2018-01-01-1.log
/a/b/c/2018-01/xyz-2018-01-01-2.log
/a/b/c/2018-01/xyz-2018-01-01-3.log
/a/b/c/2018-01/xyz-2018-01-02-1.log
/a/b/c/2018-01/xyz-2018-01-01-2.log
.
.
.
/a/b/c/2018-02/xyz-2018-02-01-1.log
/a/b/c/2018-02/xyz-2018-02-01-2.log
.
.
.
/a/b/c/2018-02/xyz-2018-02-31-1.log
/a/b/c/2018-02/xyz-2018-02-31-2.log

on a nightly basis we have to copy logs to corresponding months folder with date and tar and gzip

if the directory does not exist for the month we have to create it when copy and tar the files,

ex : /a/b/c/archieve/`date +`'%Y-%m'`/`

we should be maintaining the archived files for the last 3 days and hould be removed older than 3 days
0
Office 365 user mailbox and online archive full issue: I am the new IT manager for a company and have inherited a problem. The company has never had policies for mailbox size enforcement or archiving. I have a user with a full mailbox (49.5GB), a 180GB In Place/online archive, and ten local pst files from previous reduction attempts.

I'd like to move all older mail in to a different online archive, and free up the current mailbox and OA to function properly, be modest in size, and also establish better mail management techniques (I'll train the user in the last bit).

Plan A: I'm looking for Azure Exchange powershell commands that will move mail from the active online archive to a  new, secondary user online archive I created for him. My hope is to move all mail older than a year over to the secondary archive, which will be smaller in size than the current one, and then import the local psts in to it so that all the old emails are in one location.

Plan B: Perform the requisite tasks to switch them to the new primary and online mailboxes, leaving the original as the long term holding archive (less desirable, as I won't be able to bring all the old psts in to the almost full one).

I'm looking for powershell commands to copy from one OA to another, and optionally remove a certain date period from both main and OA.

Please ask if I haven't been clear enough about the situation or what I'm asking for. Thanks in advance!
0
Hi Experts,

I am looking for custom weblogic admin server startup script which can redirect output "directory_path/AdminServer.out" file. and rotate each time we execute the startup script so that older .out file moves to backup file.

example :

AdminServer.out
AdminServer.out0001
AdminServer.out0002
AdminServer.out0003
.....
AdminServer.out000X


Any help will be really appreciated.

Thank you
Neha
0
i need to truncate and load data into informix table .. is there a way by which i can used dbload to do it i am using a shell script to load the data .. but it always appends into the table...also i am trying to do a upshift of character data while loading itself .. but that throws error ... as syntax mismatch while using the utility.. my control file is as below



"control.file" 3 lines, 83 characters
FILE "file.unl" DELIMITER '|' 3;
INSERT INTO TAB1(name,age,salary)
VALUES (UPPER(f01),f02,f03);
0
Redirecting output ([n]>[|]word), when does "n" greater than 2 make sense?

This question is about redirecting output in bash, see: https://www.gnu.org/software/bash/manual/html_node/Redirections.html#Redirecting-Output

The general format for redirecting output is:

[n]>[|]word

I already understand the basics (you're just redirecting a file descriptor to a file for writing). But, can someone give me an example when it does make sense to use for example: 3>. In other words, if n is greater than stdin, stdout, stderr (>2), for what would you need it?

I can do:

echo 'test' 3> test-file.txt

Open in new window


This will not write anything to "test-file.txt". This is logical, because now there is just a file descriptor with number 3 pointing to test-file.txt for writing, but there is no input to fd=3 so there is also nothing to write.

The only way to give it some input is to connect file descriptor 3 for reading with a file (or connect it to the output of a pipe). But if you would do that, then fd 3 doesn't point to test-file.txt anymore. So then in the end, fd 3 was connected to test-file.txt without any reason.

So in what kind of situation it's useful to use >n with n greater than 2?
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.