Linux, FreeBSD, Juniper, Cisco / Network security articles and troubleshooting guides

FAQ
It is currently Fri Dec 15, 2017 1:37 am


News News of Shell Scripting and Programming

Site map of Shell Scripting and Programming » Forum : Shell Scripting and Programming

Tips & Tricks, Questions regarding shell scripts, awk, perl, sed and much more.

 [ Total topics 30 Go to page 1, 2, 3

Message
 Post subject: BASH shell script to mointor a directory and move file without overwriting destination
PostPosted: Wed Nov 15, 2017 7:48 am 
Hello,

So below is a bash script that will monitor a source directory for file creation and, everytime a file is created, move the file to a destination directory without overwriting the file in the destination.

Script:

$ cat move_file.sh
#!/bin/bash

src_dir=/tmp/test/src
dst_dir=/tmp/test/dst

while : ; do
ls ${src_dir} | while read file ; do
# Check if file from src dir exist in dst
i=1
stop=0
while [ $stop -ne 1 ]
do ...

Read more : BASH shell script to mointor a directory and move file without overwriting destination | Views : 53 | Replies : 0

Top
 Post subject: FreeBSD: Install python package manager (pip)
PostPosted: Fri Nov 03, 2017 6:16 am 
Code:
# python2 -m ensurepip
Requirement already satisfied: setuptools in /usr/local/lib/python2.7/site-packages
Collecting pip
Installing collected packages: pip
Successfully installed pip-9.0.1

Read more : FreeBSD: Install python package manager (pip) | Views : 67 | Replies : 0

Top
 Post subject: Shell scripting
PostPosted: Thu Aug 24, 2017 3:10 am 
Hi Friends,

I want to write a schell script for below tasks,
01. there are five tables and want to get the row count of them
02. check if the count of any table is more than 10000 mail subject need to send as RED status, if its is less than 10000 then the status should change as GREEN.

Iam new to shell scripting

Could someone help me for this?

Read more : Shell scripting | Views : 90 | Replies : 0

Top
 Post subject: AWK: How to replace a newline with actual \n
PostPosted: Thu Jul 20, 2017 11:02 am 
Code:
$ echo "
> here
> are
> multiple
> new
> lines" | awk '{printf "%s\\n", $0}'
\nhere\nare\nmultiple\nnew\nlines\n

Read more : AWK: How to replace a newline with actual \n | Views : 198 | Replies : 0

Top
 Post subject: How to use $variable in conditional sentences?
PostPosted: Wed May 17, 2017 4:01 am 
Hello all

I am doing a Makefile but I can't return the value of $var to use it in conditional sentences:

Code:
#!/bin/sh

GO=$(shell) go
GOPATH=$(GO) env GOPATH

make:
    @$(GOPATH)
    @if [ ! -d "$(GOPATH)/bin" ]; then mkdir -p "$(GOPATH)/bin" ; fi


When I type "make", @$GOPATH returns
Code:
/home/icvallejo/go
so it's ok, but after, I don't know how to use it (I can't do it) with 'if' condition, make returns this:

if [ ! ...

Read more : How to use $variable in conditional sentences? | Views : 164 | Replies : 0

Top
 Post subject: Scan IP range using nmap
PostPosted: Tue Mar 14, 2017 3:51 am 
I want to read IP address range from file. Scan these IP using nmap and store output in scan.txt file. Take only open ports with IP address from scan.txt and save it on another file.

Read more : Scan IP range using nmap | Views : 344 | Replies : 0

Top
 Post subject: Password generator with user inputs bash script
PostPosted: Thu Dec 01, 2016 5:06 am 
Hi,
I am new to bash scripting and i wanted to make a bash script that will generate a password for a user. The user must enter his/her name and the url of the site the password is used for. And the script will generate a password with those two elements in the password. So if the url is www.google.com and the name is Kevin i want google and ...

Read more : Password generator with user inputs bash script | Views : 496 | Replies : 0

Top
 Post subject: PERL: How to replace non-ascii characters/bytes in a file
PostPosted: Fri Apr 10, 2015 8:58 am 

To remove a non-ascii 9B byte in a file:


Code:
perl -i.bak -pe 's/\x9B//g' file.txt


To replace a non-ascii 9B byte with a new line:


Code:
perl -i.bak -pe 's/\x9B/\x0A/g' file.txt

Read more : PERL: How to replace non-ascii characters/bytes in a file | Views : 1315 | Replies : 0

Top
 Post subject: Echo new line in linux - supress new line or echo multiple new lines
PostPosted: Wed Jan 14, 2015 5:26 pm 
Unix implementation of the "echo" command appends a new line character at the end of the echoed text by default.

It can be changed to supress this behavior using the "-n" switch.

Echo can also be used to output one or multiple new lines with the "-e" switch which will make echo interpret "\n" sequence as new line.

Below is a list of multiple options and special sequences with ECHO:
Quote:
DESCRIPTION
Echo the STRING(s) ...

Read more : Echo new line in linux - supress new line or echo multiple new lines | Views : 2984 | Replies : 0

Top
 Post subject: SED uncomment line - How to uncomment a line or all lines with SED
PostPosted: Wed Jan 14, 2015 5:08 pm 
Sed is a very powerful linux command line tool. It is able to replace either static characters or based on regular expressions.

I will give here a few examples on how to uncomment all lines or specific line based on regular expression.

Sed uncomment all lines in a file:
Code:
user@linux:~# cat file.conf
line1
#line2
line3A
#setnence abc
sentence def
#sentence bcd
user@linux:~# sed 's/^#\(.*\)/\1/g' file.conf   
line1
line2
line3A
setnence abc
sentence def
sentence bcd
...

Read more : SED uncomment line - How to uncomment a line or all lines with SED | Views : 3767 | Replies : 0

Top
 [ Total topics 30 Go to page 1, 2, 3


Last 10 active topics


Shell Scripting and Programming

No new posts BASH shell script to mointor a directory and move file without overwriting destination
View the latest post
No new posts FreeBSD: Install python package manager (pip)
View the latest post
No new posts Shell scripting
View the latest post

OpenLDAP - Lightweight Directory Access Protocol

No new posts Synchronize OpenLDAP and Microsoft Active Directory
View the latest post

Routing and dynamic routing protocols

No new posts BGP Notification Message (3), length: 21, OPEN Message Error (2), subcode Authentication Failure
View the latest post
No new posts JUNOS BGP: How to drain a BGP peering router gracefully without bgp session reset
View the latest post

TCP/IP Networking

No new posts Problem pinging and using server with mobile hotspot
View the latest post

Memory, Storage, Backup and Filesystems

No new posts FreeBSD: List disk drives and re-scan after adding hot-add disk (in virtual environments)
View the latest post

Apache, Nginx, Lighttpd and other web server software

No new posts NGINX: 413 Request Entity Too Large
View the latest post

System administration

No new posts MAC OS X: read image/jpeg EXIF information on command line
View the latest post

Login

Username:   Password:   Log me on automatically each visit  

Statistics

Statistics

Total posts 612 | Total topics 982 | Total members 1192



News News Site map Site map SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list


Delete all board cookies | The team | All times are UTC - 5 hours [ DST ]



phpBB SEO