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

FAQ
It is currently Sun Aug 20, 2017 6:18 pm


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 27 Go to page 1, 2, 3

Message
 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 : 54 | 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 : 66 | 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 : 234 | 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 : 320 | 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 : 1126 | 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 : 2788 | 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 : 3309 | Replies : 0

Top
 Post subject: Wget error: ERROR: The certificate of is not trusted.
PostPosted: Wed Jan 14, 2015 6:23 am 
Wget error: ERROR: The certificate of is not trusted / Skipping ssl/tls certificate checks with wget

Some webmasters use self signed or own CA signed certificates for trivial websites. Such example is xcache website:

Code:
# wget https://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz
--2015-01-14 05:18:48--  https://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz
Resolving xcache.lighttpd.net (xcache.lighttpd.net)... 188.40.103.19, 2a01:4f8:100:8082::2
Connecting to xcache.lighttpd.net (xcache.lighttpd.net)|188.40.103.19|:443... connected.
ERROR: The certificate of `xcache.lighttpd.net' is not trusted.
ERROR: The certificate of `xcache.lighttpd.net' hasn't got a known issuer.


This can be solved by ...

Read more : Wget error: ERROR: The certificate of is not trusted. | Views : 7666 | Replies : 0

Top
 Post subject: Linux / FreeBSD: Avoid bash history duplicate lines with HISTCONTROL
PostPosted: Mon Jan 12, 2015 12:01 pm 
Linux / FreeBSD: Avoid bash history duplicate lines with HISTCONTROL

Please see previous article "How to increase bash history size in Linux" /how-to-increase-bash-history-size-in-linux-t19491.html first.

Bash history, by default, is 500 lines long. Running the same command multiple times, consume multiple bash history entries. Example:

[user@linux ~]# one-command
-bash: one-command: command not found
[user@linux ~]# one-command
-bash: one-command: command not found
[user@linux ~]# one-command
-bash: one-command: command not found
[user@linux ~]# one-command
-bash: one-command: command ...

Read more : Linux / FreeBSD: Avoid bash history duplicate lines with HISTCONTROL | Views : 546 | Replies : 0

Top
 Post subject: How to increase bash history size in Linux
PostPosted: Mon Jan 12, 2015 11:45 am 
How to increase bash history size in Linux

This tutorial has been tested on Debian and Centos / Rhel Linux.

Default Linux history size is 500 commands ( rows ).
Code:
# set | grep HIST
HISTFILE=/root/.bash_history
HISTFILESIZE=500
HISTSIZE=500



To increase this limit to 10k for example, I use the /etc/profile.d config directory for bash source files.
Code:
# vim /etc/profile.d/bash_hist.sh     
export HISTSIZE=10000
export HISTFILESIZE=10000

I use the "export" keyword to make this ...

Read more : How to increase bash history size in Linux | Views : 8390 | Replies : 0

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


Last 10 active topics


Shell Scripting and Programming

No new posts AWK: How to replace a newline with actual \n
View the latest post
No new posts How to use $variable in conditional sentences?
View the latest post
No new posts Scan IP range using nmap
View the latest post
No new posts Password generator with user inputs bash script
View the latest post

Virtualization

No new posts SSH Login to Vmware ESXi with ssh keys
View the latest post
No new posts How to retrieve Vmware ESXi license from ssh shell command line
View the latest post

TCP/IP Networking

No new posts TCP ack after two packets
View the latest post

Junos Tips & Tricks

No new posts MTR / My traceroute in Junos
View the latest post

VPS Hosting & Security

No new posts Host a gmod server on a vps or shared host?
View the latest post

Juniper virtual MX (vMX)

No new posts Juniper Virtual MX (vMX) 14.2R5.3 Phase 2 (RE and MPC on different VMs)
View the latest post

Login

Username:   Password:   Log me on automatically each visit  

Statistics

Statistics

Total posts 601 | Total topics 970 | Total members 1193



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