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

FAQ
It is currently Tue Jan 28, 2020 12: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 31 Go to page 1, 2, 3, 4

Message
 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 : 6655 | 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 : 20651 | 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 : 1664 | 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 : 19944 | Replies : 0

Top
 Post subject: How to convert pdf to text in FreeBSD
PostPosted: Thu Jan 08, 2015 10:03 am 
How to convert pdf to text in FreeBSD

A simple tool to extract or convert text from a pdf file (unprotected) to a text file is using "xpdf" port.

Code:
# cd /usr/ports/graphics/xpdf && make install clean

Opt out "X11 (graphics) support" if you're not interested in X11 support.

Example of converting pdf file to test file:

# ls
simple.pdf
# /usr/local/libexec/xpdf/pdftotext simple.pdf
# ls
simple.pdf simple.txt
# cat simple.txt
A Simple PDF ...

Read more : How to convert pdf to text in FreeBSD | Views : 2731 | Replies : 1

Top
 Post subject: How to add line numbers in unix shell output
PostPosted: Fri Oct 31, 2014 5:31 am 
How to add line numbers in unix shell output

To display line numbers easily on a shell output, pipe it to "nl" command - line number filter.

Quote:
NL(1) FreeBSD General Commands Manual NL(1)

NAME
nl -- line numbering filter

SYNOPSIS
nl


DESCRIPTION
The nl utility reads lines from the named file or the ...

Read more : How to add line numbers in unix shell output | Views : 2231 | Replies : 0

Top
 Post subject: How to replace dot or any character with AWK
PostPosted: Tue Jan 28, 2014 6:35 am 
Code:
echo 'This is a sentence. This is another sentence.' | awk  '{gsub(/\./,"",$0);print $0}' 
This is a sentence This is another sentence

Few notes:
- "gsub" is a string subroutine in awk. It requires at least three parameters: 1: the regular expression match, 2: the substitution and 3: the target string that is subject for substitution
- the substitution requires double quotes.

Below I'm replacing the "dot" character and also omitting the new line:
# echo ...

Read more : How to replace dot or any character with AWK | Views : 15087 | Replies : 0

Top
 Post subject: grep match pattern: Binary file bincharacters.txt matches - How to make grep treat a file as text
PostPosted: Wed Dec 11, 2013 7:15 am 
Code:
# grep text bincharacters.txt
Binary file bincharacters.txt matches


How to make grep treat a a text file containing binary characters as text and display the matching lines:
Code:
# grep -a text bincharacters.txt
context_verf_err                0

Read more : grep match pattern: Binary file bincharacters.txt matches - How to make grep treat a file as text | Views : 1646 | Replies : 0

Top
 Post subject: Juniper SRX - Perl script - SNMP based RRDtool graphis from CPU usage and Flow Session (current)
PostPosted: Mon Nov 04, 2013 11:43 am 
Below is a simple perl script that queries queries a Juniper branch SRX box (210 in my case) for current data plance CPU usage as well as current flow numbers and creates RRDtool graphics based on the results.

# cat collect_srx_usage.pl
#!/usr/bin/perl
# This script pols a Juniper SRX branch device for Current Flow sessions and Data Plane CPU usage.

use RRDs;

# RRD databases location
my $rrd = '/var/home/www/static_pages/mrtg_graphs/rrd';
# images location
my $img ...

Read more : Juniper SRX - Perl script - SNMP based RRDtool graphis from CPU usage and Flow Session (current) | Views : 4735 | Replies : 1

Top
 Post subject: Removing new line / EoL characters in a PERL script
PostPosted: Mon Nov 04, 2013 6:47 am 
Use either of the two methods (probably more) of removing new line characters from an input in a perl script
Code:
my $line = "This contains a new line. \r\n";
chomp($line);

or
Code:
my $line = "This contains a new line. \r\n";
$line =~ .s/[\x0A\x0D]//g;

Read more : Removing new line / EoL characters in a PERL script | Views : 3710 | Replies : 0

Top
 [ Total topics 31 Go to page 1, 2, 3, 4


Last 10 active topics


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

Routing and dynamic routing protocols

No new posts JUNOS BGP: How to drain a BGP peering router gracefully without bgp session reset
View the latest post

TP-Link JetStream Switching

No new posts TP-Link TL-SG3210 How to configure ARP Inspection, DHCP Snooping and ARP Scanning
View the latest post
No new posts TP-Link JetStream SG3210 V2.0 CLI, User Guide downloads
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

Shell Scripting and Programming

No new posts Shell scripting
View the latest post
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

Virtualization

No new posts SSH Login to Vmware ESXi with ssh keys
View the latest post

Login

Username:   Password:   Log me on automatically each visit  

Statistics

Statistics

Total posts 617 | Total topics 987 | 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