shell scripting basics

Learn about shell scripting basics, we have the largest and most updated shell scripting basics information on alibabacloud.com

A set of Linux Shell scripting little Exercises

spaces. If IFS is null, the parameters is joined without intervening separators.oldifs= "$IFS" ifs= "" array= ($result) ifs= "$oldIFS" for I in ${array[@]}; Doecho $idone# Use Facter to get a set of Key-value# Facter output has a newline character, you must replace the newline character with a space# Replace newline characters with spaces to use awk or sed# awk-v rs= "" ' {gsub ("\ n", "");p rint} '# ECHO-E "2 \n1" | Sed ': A; n;$!ba;s/\n//g 'result=$ (facter | awk '/ipaddress/!/ipaddress_lo/{p

Shell Scripting Encryption

#shc是一个专业的加密shell脚本的工具. Its role is to convert the shell script into an executable binary file, which is a good solution to the script contains IP, password and so do not want to open the problem.HTTP://WWW.DATSI.FI.UPM.ES/~FROSAL/SOURCES/SHC's official websitewget http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.9.tgzTAR-XF shc-3.8.9.tgzCD shc-3.8.9Mkdir-pv/usr/local/man/man1#这步是必须的, because SHC will ins

Shell Scripting Practices

Common shell scripting use cases, from the online reference and after the modification of the work, in addition to the wiki in the company to write records, it is necessary for a blog to record a drop.Combat Problem 1:Use the For loop to create a batch of 10 files in the/oldboy directory, with the name in turn:Oldboy-1Oldboy-2......Oldboy-10Answer:[[Email protected]]# cat 1.sh#!/bin/bashFor iin ' seq 1 10 '

[Consolidate shell Basics] shell Basics

[Consolidate shell Basics] shell Basics Address of this Article Sharing outline: 1. Functions in shell 2. array in shell 3. Variables in shell 4. Operators in

Redhat Shell Scripting Exercises

file not found and then exit and return the corresponding value4. Created user login shell for/bin/false5. This script does not need to set a password for the user6. You can get the user name list as a test Http://rhgls from the URL below. Domain11.example.com/materials/userlistVim mkusers.sh#! /bin/bashIf [$#-eq 0];thenEcho ' Usage:/root/mkusers 'Exit 1Fiif [!-F $]; ThenEcho ' Input file not found 'Exit 2FiWhile Read lineDoUseradd-s/bin/false $lineD

To partition a hard disk using Shell scripting Automation

, This command keeps the command that is about to jump to another shell terminal to continue running in this terminal.The end of the logo is EOFThe two empty lines in the middle represent the carriage return, the default meaning.1 umount/dev/mmcblk1p1 2 /dev/ mmcblk1p13 umount/ dev/mmcblk1p2

Automating the deployment of DHCP services with Shell scripting, plus text-to-document verification

; "src=" Http://s3.51cto.com/wyfs02/M01/6D/71/wKioL1VkgxWDcoX1AAFFm2II9Jg092.jpg "title=" Iiii.png "alt=" Wkiol1vkgxwdcox1aaffm2ii9jg092.jpg "/>2 Restarting the DHCP serviceService DHCPD Restart650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6D/71/wKioL1Vkg-nSFvTyAACA2JR08T8552.jpg "title=" yy.png "alt=" Wkiol1vkg-nsfvtyaaca2jr08t8552.jpg "/>3 Authenticating the ClientService Network restart650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6D/75/wKiom1VkgtmwUhKTAAJ5iQ_rdLg175

Ubuntu uses shell scripting to copy a class of files from all directories in the current directory to the same directory

There are some files and directories under the current directory, each of which has several. txt files in each directory.It is now required to create a new directory in the current directory all, and all of those directories will have a. txt fileare copied to the directory all. The shell script in ubuntu12.04 is implemented as follows:#!/bin/sh# Hint Informationecho "Start:"# define VariablesDst=allPst=.txt# Copy files to destination folderIf [-D ${DS

About shell scripting when value too great for base (Error token is "08")

A problem was encountered today when writing a timed CP script, value too great for base (Error token is "08")The number system that originally started with 0 is recognized by default as an octal number, so my $datem-1 gets the month of the month in return: value too great for base (Error token is "08") This error, the solution isThe $datem format or the declaration is called decimal, ' 10# $datem '-1 so it can. That is, the variable or number that will be converted to decimal is preceded by a '

Shell Scripting compilation

-i ' $myline ' s/$/\a\nupstream fdfs_group1 {\ n server ' $tempvar ': 8080;/'/root/my/mybin/sbin/test.configSed ' 3a 123 ' 1.txtSed-i ' $myline ' a\nupstream fdfs_group1 {\ n server ' $tempvar ': 8080; '/root/my/mybin/sbin/test.configFive, the operation of the variableThe operation should be placed in square bracketsKnown variable myline, the variable plus 2 should be written as: $[myline+2]Vi. Replace the value of a string that appears several timesUnlimited:Sed-e ': a;/\ (. *abc\) \{3\}/{s/abc

Non-interactive scripting with Shell combined with expect

Simple needs to explain shell+expectInstall the Expect,yum installation firstYum Install Expect-y#!/bin/baship= ' 192.168.80.20 ' #定义远程交换服务器的IPpassword= ' [email protected] ' #定义输入的密码Expect Spawn ssh [email protected] $ip ls #在expect中执行命令Set Timeout-1 #定义超时时间, 1 is never timed outExpect "*:" #如果输出 *:Set Timeout-1Send "$password \ r" #自动输入passwordExpect EOF #结束EofThis article is from the "Eight Miles" blog, so be sure to keep this source http://5921271

Bash Shell Scripting Learning (ii)

;NBSP;STATU=0NBsp;| |statu=1if[ "$statu" == "0" ];then echo $filename exists and is a directory. "rm -rf "$path/$filename" echo "deleted this directory! "else echo "$filename exists and is a file, deleting and creating a directory with the same name " rm-f "$path/$filename" mkdir "$path/$filename" echo "Creating now Please ..." echo "$filename Catalogue has been established! "fi ;; esacFor simple instructions, write the logic of the script. Use the TEST-E command to determine if the "log

Shell Scripting Learning Notes (advanced usage of SED----mode space and hold space)

original content). The final result is consistent with the results we see. 2. Transformation of Ranks Let me explain the above statement, h means that the content of the pattern space is appended to the hold space, ${...} means the last execution, which means that the contents of {} are executed last, so the contents of the space are consistent with the contents of cat in the last time,x Represents the content of the swap hold space and pattern space , then the contents of the patte

View all users under Linux (Shell scripting get)

In Linux systems, the two most important files for user account management are/etc/password and/etc/shadow.In the/etc/password file, each line represents an account, but there are many accounts that are system accounts. Like what:Bin, ADM, etc., as well as administrator account root. The rest is for general user accounts.Each line is composed of (to: Split):1 account name;2 password (combined with/etc/shadow);3 UID User ID, where 0 is the root, 1~499 is the system user account, and the general u

Shell scripting topics-----------fully automated compilation and installation of MySQL

/local/mysql/--datadir=/usr/local/mysql/data/--user=mysql ls/usr/ Local/mysql/data/ln-s/usr/local/mysql/bin/*/bin/service mysqld start echo "Now let ' s begin mysql_secure_installation "If [! -e/usr/bin/expect] then yum install expect-y fi echo ' #!/usr/bin/expect set timeout set password [lindex $argv 0 ] Spawn mysql_secure_installation Expect {"Enter for none" {send "\ r"; exp_continue} "y/n" {send "y\r"; Exp_continue} "Password" {send "$password \ r"; Exp_continue} "cleaning up" {send "\ r"}

Shell Scripting Learning Notes (3) Use of SED commands

{Command1Command2Command3}CommentsAs with the shell, the comment uses the #Replace[Address] S/pattern/replacement/flagsThis means that the part of the address line that matches the pattern is replaced with replacement.Of these, flags have several values:A number from N 1 to 512 that represents the substitution of the nth occurrence of the specified pattern in this mode.G makes a global change to all occurrences of the pattern space, and by default onl

Shell Scripting Learning

To see what versions of the Shell:cat/etc/shells system are currently running, the first process that starts is initHow bash Shell debugs:Simply add parameters after the SH command-N: Do not execute scripts, query the grammar within the scripts, if there are errors are listed!-V: The contents of scripts are displayed on the screen before executing the scripts;-x: The scripts content that will be used is displayed on the screen, slightly different from

Shell Scripting Learning

' test.in//Print line 3rd to 5th Sed–n '/hello/p ' test.in//print out lines containing hello Sed–n '/hello/= ' test.in//print out line numbers with Hello Sed–n '/hello/d ' test.in//delete the line containing Hello Sed Common editing commands The SED replace command uses the format "Address" s/old word/new word/"GPW" Address: If omitted, indicates that all rows are edited G: Global substitution, default means replacing only the first word to match P: Print the modified line W fname: Writes the

Shell scripting monitors memory and sends messages

1. Prepare the tool to send the message:#!/usr/bin/python#-*-Coding:utf-8-*-Import SysImport SmtplibImport Email.mime.multipartImport Email.mime.textServer = ' smtp.163.com 'Port = ' 25 ' def sendmail (server,port,user,pwd,msg): SMTP = Smtplib. SMTP () Smtp.connect (server,port) Smtp.login (user, pwd) Smtp.sendmail (msg[' from '], msg[' to '], msg.as_string ()) Smtp.quit () Print (' Mail sent successfully email has send out! ') if __name__ = = ' __main__ ':msg = Email.mime.mul

Shell Scripting Raiders (learning notes)--1.6 math and BC commands

requires the output on the screen to be "1+2+3+4+5+6+7+8+9+10= calculation results", which is a good example. [[emailprotected] tmp]# echo $ (seq -S " + " 10 " = ' seq -S " + " Ten | BC " 1 +2 +3 +4 +5 + 6 +7 +8 +9 +10 = 55 Echo $ (seq"+") =$ (('seq'+ "ten"))1+2+3+4+5+6 +7+8+9+Ten=[Email protected] tmp]#Echo$(seq-S"+" Ten)=$(seq-S" + " Ten|Xargs Expr) # Note"+"And" + "1+2+3+4+5+6+7+8+9+Ten= -Back to series article outline:http://www.cnblogs.com/f-ck-need-u/p/7048

Total Pages: 15 1 .... 10 11 12 13 14 15 Go to: Go

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.