[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

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

I'll need a Shell (Bash) script (rather an exact command) that outputs

a)  files' name in the Solaris system, one file per line in the UNIX systems
b) that were modified/created the last 1470 minutes
c) exclude FIFO files, symbolic links, sockets (ie *.sock)
d) names of files of between 1 byte to 20MB in size
e) files in /dev, /devices, /kernel, /cdrom, /platform, /proc, /net
f) files mounted on NFS

I have about 1million files so hoping the command/script of outputting
the file can complete in 30mins, so may need efficient coding.


I need to amend the following script to read (ie for AV to scan) the above output file:

#!/bin/bash
LOGFILE="/var/log/clamav/`hostname`-$(date +'%Y-%m-%d').log";
## suggest to change dirs below to root but exclude databases
DIRTOSCAN="/var /opt /home /etc /tmp /export";

for S in ${DIRTOSCAN}; do
DIRSIZE=$(du -sh "$S" |grep -v "/proc" |grep -v "/dev" |grep -v ...  /2>/dev/null | cut -f1);
## add to grep -v for any other file types to exclude

echo "Starting a daily scan of "$S" directory.
Amount of data to be scanned is "$DIRSIZE".";

clamscan -ri "$S" >> "$LOGFILE";
0
Learn SQL Server Core 2016
LVL 12
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.

Dear Experts,

I am thinking to use SSIS to do the following procedure.

(1) copy many files to Linux machines. then
(2) execute a Linux program (command) to analysis those files. The program will output the result to the local Linux drive
(3) when (2) is done, then pull the result back to Windows machine

For (1) I am thinking of FTP task (by FTP or SFTP)

how about the task of (2) and (3) ?  Could you please help ... Thanks
0
Linux. I need to set up a script that I can run via cron in the middle of every night to copy / back up specific folders into another directory. I want all folders, files and permissions and attributes copied. The goal is to have a 24 hour old copy that I can restore in case a user screws up their files. Example:

/usr/home/thisuser/web_master would be copied / backed up to /usr/home/mainuser
/usr/home/thisotheruser/web_master would be copied / backed up to /usr/home/mainuser
/usr/home/andanotheruser/web_master would be copied / backed up to /usr/home/mainuser

Each night, the copy / back up would overwrite the one from 24 hours ago.

How do I set this script up, and what type of file extension should the script be?
0
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
I have a list of file names that i loop through and move to a destination directory.   Now i need to look for files that have *_NTL*  in the file name and then do something.  

I have this.

if [ ${archive_dir}/$name 2>/dev/null ]
      then
       cp ${archive_dir}/$name ${data_dir}/NTL_${filename}_${DateTime}.csv
      else
      cp ${archive_dir}/$name ${dest_dir}$_{filename}_${DateTime}.csv
fi

any assistance what i am doing wrong, would be great.

Thanks,
bje
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
Bootstrap 4: Exploring New Features
LVL 12
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

By default, the first three rows of a "file descriptor table" consists of:

FD 0 (standard input,  associated with keyboard)
FD 1 (standard output, associated with screen)
FD 2 (standard error,  associated with screen)

Open in new window


These file descriptors point to one or more rows in the "open file table". Imagine we only have these three file descriptors. Then how does the "open file table" look like?

Usually all three file descriptors point to the same file, but that doesn't mean they point to the same entry in the "open file table". So how the open file table looks like?

_ | offset | reference count | permissions | flags | pointers
_ |    ?   |        ?        |      ?      |   ?
possible more rows

Open in new window


The lsof command shows for example:

lsof        721    root    0u      CHR              136,1       0t0          4 /dev/pts/1
lsof        721    root    1u      CHR              136,1       0t0          4 /dev/pts/1
lsof        721    root    2u      CHR              136,1       0t0          4 /dev/pts/1

Open in new window


The file "/dev/pts/1" is CHR (character special file). They all point to the same file.
I'm also wondering why it's for example "0u" and not "0r"? The file descriptor 0 stands for input, so it only has to read something.

r for read access;
w for write access;
u for read and write access;

Open in new window


I would expect something like: 0r, 1w, 2w instead of 0u, 1u, 2u? And what are the offsets et cetera?
0
[root@myserver~]# /bin/ksh
# echo $SHELL
/bin/bash

I wonder why ksh is not showing up when i did ksh or /bin/ksh?

I am used with bash, specific app uses ksh so i had to switch.
0
Batch file to ping all network hosts to determinate witch are powered up and store output to a text file

Hello, I need to write a Batch file to ping all network hosts (readed from a hostslist.txt) and write UP/DOWN state to a text file.
0
how to configure aws configure in docker file

my docker file

FROM ubuntu


RUN apt-get update && apt-get install -y awscli


cmd docker pull mariadb
cmd  docker pull mysql
CMD ["/test.sh"]

test.sh
 aws configure set aws_access_key_id default_access_key xxxxxx
 aws configure set aws_secret_access_key default_secret_key xxxxxx
aws configure set default.region us-west-2
 
aws s3 cp s3://mariadbs3bucket/test.txt /test

 mysql -u xxx-pxxx --host xxx -P 3306  --socket=TCP/IP  -e "USE myDB; insert into myDB.tt values(50000);"

the above both command are working fine while running in ec command line
there i have set the aws configure
0
data no align after i do cat in unix this is my script
cat data*.txt|grep -v ^UNIT_CDE|awk '{print $1,",",$2,",",$3,","$4,",",$5,",",$6,",",$7,",",$8,",",$9,","$10,",",$11,",",$12,",",$13,",",$14,",",$15,","$16,",",$17,",",$18,",",$19,",",$20}' >>  mergetstneg.txt
catfileimg.jpg
0
I need to write a shell script to login to 5 linux servers using ssh and run a command remotely.

ssh keys are already.  key less authentication is setup already.
0
See: https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond


-h
Is symbolic link, bash convention.
See -l.


-l
Is symbolic link.
Treats the TestString as a pathname and tests whether or not it exists, and is a symbolic link. May also use the bash convention of -L or -h if there's a possibility of confusion such as when using the -lt or -le tests.


-L
Is symbolic link, bash convention.
See -l

What are the differences between these three?

"-h" has "bash concention" and "-l" not. But what is the difference in practise? Can someone give me an example of the difference?

And why it's "-L" and not "-H"? "-L" is about the bash convention, but "-l" not. However, "-h" is. So then I would expect "-H" instead of "-L".

I don't need it for something right now, but I'm trying to understand the Apache documentation.
0
Hello,

I need to run this command in a multiple linux server :

id -u user2 &>/dev/null || useradd -c "SSH account" -d /home/tools user2; echo 'password2' | passwd user2 --stdin

The idea is to create a text file with some IPs one per line and running the above command for each IP

But in somes linux servers, I can directly login as root@ip without password, but others linux servers I need to log as specific user@ip with password and switch to root

Any idea to do that ?
0
I want to write a init script to stop and start the MongoDB.
0
HTML5 and CSS3 Fundamentals
LVL 12
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

when i start the application using a specific command, its does spawn a process however a i am not getting the prompt back.  I have been told you to press CTRL+C to get the prompt.

This is usual behavior for starting the application.

How do i get the prompt back using the shell script?

[root@myserver]# bash -x /etc/init.d/app start
....
output omitted

^C
Session terminated, killing shell... ...killed.


when i run #ps -ef | grep app, i noticed the process is running. when i talk to the app support, they said its normal behavior.  Not sure why this happens.
0
I am working on script where i have to create a init script to start/stop the application. However the application does not stop properly. i had to kill 3 - 4 process by grepping the PID ids.

How can i do this?
0
I want to know how can I start a script at the system startup. I tried to make a sh file under /etc/rc.d/rc3.d/ but I rebooted the Os and it does not start my script as I want. :(.

Regards,
0
simple Shell script to start a tom cat server (JVM) and if for some reason if server does not start within 3 mins exit and  also find any hung jvm tomcat start commands fired and force kill it.
0
Hello,
Im trying to translate this code from https://securionpay.com/docs/api#checkout-request-sign.
EXAMPLE SIGNING


export checkout_request='{"charge":{"amount":499,"currency":"EUR"}}'
export signature=`echo -n "$checkout_request" | openssl dgst -sha256 -hmac 'pr_test_tXHm9qV9qV9bjIRHcQr9PLPa' | sed 's/^.* //'`
echo -n "$signature|$checkout_request" | base64
        

EXAMPLE SIGNED CHECKOUT REQUEST


Y2Y5Y2UyZDgzMzFjNTMxZjgzODlhNjE2YTE4Zjk1NzhjMTM0Yjc4NGRhYjVjYjdlNGI1OTY0ZTc3OTBmMTczY3x7ImNoYXJnZSI6eyJhbW91bnQiOjQ5OSwiY3VycmVuY3kiOiJFVVIifX0=
				

Open in new window


to Ruby on Rails

I ended with

       
 checkout_request='{"charge":{"amount":5,"currency":"EUR","capture":true}}'
 secret_key = 'sk_test'
 @signature = Base64.urlsafe_encode64(OpenSSL::HMAC.hexdigest('sha256', checkout_request, secret_key) + "|" + checkout_request)

Open in new window


which isn't valid and its not exacly translation of the script.

When i test shell version with my secret key it works.
I tried Base64.urlsafe_encode64, encode64, strict_encode65, I tried digest instead of hexdigest. All kinds of way because I desperatly can't make it work. I think its about checkout_request data because it translates to this
 
2.5.0 :001 > '{"charge":{"amount":5,"currency":"EUR","capture":true}}'
 => "{\"charge\":{\"amount\":5,\"currency\":\"EUR\",\"capture\":true}}" 

Open in new window

and therefore signature is created with `\` before quote

question on stackoverflow: https://stackoverflow.com/questions/51506282/json-and-generating-signature
0
Looking for a script to bulk disable UAC and reboot remote servers so we can run remote installs. Looking at powershell as one scripting method since available on servers. Can look at also ding WMI.  Just any solution would be great better than doing it manual for each one. The good news we are admins on all the servers.
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.