欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

接触到的 公司里别人写的 shell脚本 有大用 有大大用 有大大大用

修改时区 Modify Time Zone

sudo systemsetup -settimezone "America/Los_Angeles




0629_ipconfig


#!/bin/bash



# 获取当前IP地址

current_ip=$(ipconfig getifaddr en0) # 这里假设使用en0接口



# 授权IP地址列表

authorized_ips=("192.168.0.100" "192.168.0.101" "192.168.0.102") # 根据实际情况修改



# 检查当前IP地址是否在授权列表中

if [[ ! " ${authorized_ips[@]} " =~ " ${current_ip} " ]]; then

    # 当IP地址未经授权时执行关闭网口操作

    networksetup -setnetworkserviceenabled Ethernet off

fi



networksetup -listallhardwareports | grep Device | awk '{print $2}





11

#!/bin/bash

time=`date +"%Y-%m-%d"`

a='.*n207.*|.*n208.*|.*n210.*|.*le2.*|.*la4.*'

if [ ! -d  /tmp/newmount_CpFile ]; then

    mkdir /tmp/newmount_CpFile

fi



mount -w -t smbfs //jdpd:p-0p-0p-0p-0p-0@192.168.7.20/ESNPIFILECOPY$/EFFA /tmp/newmount_CpFile

mkdir -p /tmp/newmount_CpFile/$HOSTNAME\_$USER/$time\_Documentbackup

touch    /tmp/newmount_CpFile$HOSTNAME\_$USER/$time\.txt

find -E / -iregex "$a" ! -path "/mnt/*" ! -path "/System/*" ! -path "/Applications/*" ! -path "/private/*" -print0 | xargs -0 -I F CP "F"  /tmp/newmount_CpFile/$HOSTNAME\_$USER/$time\_Documentbackup

find -E / -iregex "$a" ! -path "/mnt/*" ! -path "/System/*" ! -path "/Applications/*" ! -path "/private/*"  >> /tmp/newmount_CpFile/$HOSTNAME\_$USER/$time\.txt





#if [[ `cat /tmp/newmount_CpFile/$time\.txt |wc -l` -eq 0 ]];then

#rm -rf  /tmp/newmount_CpFile/$HOSTNAME\_$3/$time\.txt

#fi

diskutil unmount /tmp/newmount_CpFile





20220729_ES


#!/bin/bash

time=`date +"%Y-%m-%d"`

a='.*n197.*|.*n198.*|.*n199.*|.*le1.*|.*la3.*'

if [ ! -d  /tmp/newmount_CpFile ] ; then

    mkdir /tmp/newmount_CpFile

fi



mount -w -t smbfs //$4:$5@192.169.12.31/esnpifilecopy$/MP /tmp/newmount_CpFile

mkdir -p /tmp/newmount_CpFile/$HOSTNAME\_$3/$time\_Documentbackup

touch    /tmp/newmount_CpFile$HOSTNAME\_$3/$time\.txt

find -E / -iregex "$a" ! -path "/mnt/*" ! -path "/System/*" ! -path "/Applications/*" ! -path "/private/*" -print0 | xargs -0 -I F CP "F"  /tmp/newmount_CpFile/$HOSTNAME\_$3/$time\_Documentbackup

find -E / -iregex "$a" ! -path "/mnt/*" ! -path "/System/*" ! -path "/Applications/*" ! -path "/private/*"  >> /tmp/newmount_CpFile/$HOSTNAME\_$3/$time\.txt





#if [[ `cat /tmp/newmount_CpFile/$time\.txt |wc -l` -eq 0 ]];then

#rm -rf  /tmp/newmount_CpFile/$HOSTNAME\_$3/$time\.txt

#fi

diskutil unmount /tmp/newmount_CpFile








ADD-admin
#!/bin/sh



dseditgroup -o edit -a HWTE -t user admin







ADD-admin copy

#!/bin/sh



dseditgroup -o edit -a 1111111 -t user admin







ADD-admin-current

dseditgroup -o edit -a $3 -t user admin





Add-Admin2


#!/bin/sh



uname=`ls  -lt /Users | grep js- | head -1  | rev | cut -d ' ' -f1 |rev`



# first secret



dscl . merge /Groups/admin users ${uname}



dscacheutil -flushcache




ADD-SECadmin

#!/bin/sh



dseditgroup -o edit -a Dillen -t user administrator





Audit_iMessage_PIC

#!/bin/bash



username=$4

password=$5



if [ ! -d  /tmp/newmount ] ; then

    mkdir /tmp/newmount

fi

mount -w -t smbfs //$4:$5@192.168.18.19/imessage$ /tmp/newmount

mv /Users/$3/Library/Messages/Attachments/ /tmp/newmount/$3

diskutil unmount /tmp/newmount





Audit_iMessage_PIC for RM -R


#!/bin/bash





#rm -r /Users/*/Library/Messages/Attachments



rm -r /Users/$3/Library/Messages/Attachments








Deny WiFi  禁用 禁止 wifi


networksetup -setnetworkserviceenabled Wi-Fi off

networksetup -setairportpower en0 off




CZ-SSID-NPI only


#!/bin/bash

# set the allowed SSID bbbb-NPI

allowed_ssid1="bbbb-NPI"

##Get the wireless port ID

wifi_port=$(networksetup -listallhardwareports | awk '/Wi-Fi|AirPort/{getline; print $NF}')

# current preferred SSID list

ssid_list=`networksetup -listpreferredwirelessnetworks $wifi_port | tail -n +2 | cut -c 2-`

# current connected SSID

connected_ssid=`networksetup -getairportnetwork $wifi_port | cut -c 24-`

# clean up ssid

IFS=$'\n'

for ssid in $ssid_list

do  

    if [ "$ssid" != "$allowed_ssid1" ]

    then

        networksetup -removepreferredwirelessnetwork $wifi_port $ssid

        security delete-generic-password -a $ssid -D "AirPort network password"

        #echo $ssid Not allowed, and removed

    #else

        #echo $ssid is allowed

    fi

done



if [ "$connected_ssid" != "$allowed_ssid1" ]

then

    networksetup -setairportpower $wifi_port off

    networksetup -setairportpower $wifi_port on

fi







Audit_iMessage_PIC MP


#!/bin/bash



username=$4

password=$5



if [ ! -d  /tmp/newmount ] ; then

    mkdir /tmp/newmount

fi

mount -w -t smbfs //$4:$5@192.168.7.2/jses$ /tmp/newmount

mv /Users/$3/Library/Messages/Attachments/ /tmp/newmount/$3

diskutil unmount /tmp/newmount





Audit_iMessage_PIC NPI


#!/bin/bash



username=$4

password=$5



if [ ! -d  /tmp/newmount ] ; then

    mkdir /tmp/newmount

fi

mount -w -t smbfs //$4:$5@192.168.18.19/imessage$ /tmp/newmount

mv /Users/$3/Library/Messages/Attachments/ /tmp/newmount/$3

diskutil unmount /tmp/newmount






Audit2MP


#!/bin/bash

time=`date +"%Y-%m-%d"`

a='.*n197.*|.*n198.*|.*n199.*|.*le1.*|.*la3.*'

if [ ! -d /ESAudit/$HOSTNAME\_$USER/$time\_Documentbackup ];then

  mkdir -p /ESAudit/$HOSTNAME\_$USER/$time\_Documentbackup

  touch /ESAudit/$HOSTNAME\_$USER/$time\_Documentbackup/$time\.txt

else

  echo "文件已存在"

fi

find -E / -iregex "$a" ! -path "/mnt/*" ! -path "/System/*" ! -path "/Applications/*" ! -path "/private/*" -print0 | xargs -0 -I F CP "F"  /ESAudit/$HOSTNAME\_$USER/$time\_Documentbackup

find -E / -iregex "$a" ! -path "/mnt/*" ! -path "/System/*" ! -path "/Applications/*" ! -path "/private/*"  >> /ESAudit/$HOSTNAME\_$USER/$time\_Documentbackup/$time\.txt



if [[ `cat /ESAudit/$HOSTNAME\_$USER/$time\_Documentbackup/$time\.txt |wc -l` -eq 0 ]];then

  rm -rf  /ESAudit/$HOSTNAME\_$USER/$time\.txt

fi



#!/usr/bin/expect

expect -c "

  spawn scp -r /ESAudit/$HOSTNAME\_$USER/$time root@192.168.2.54:/haihua/MP

  expect {

    \"*assword\" {set timeout 30; send \"password\r\";}

    \"yes/no\" {send \"yes\r\"; exp_continue;}

  }      

  expect eof"

       

rm -rf /ESAudit/*





Audit2Office_local


#!/bin/bash

time=`date +"%Y-%m-%d"`

a='.*n197.*|.*n198.*|.*n199.*|.*le1.*|.*la3.*'

if [ ! -d /ESAudit/$HOSTNAME\_$USER/$time\_Documentbackup ];then

  mkdir -p /ESAudit/$HOSTNAME\_$USER/$time\_Documentbackup

  touch /ESAudit/$HOSTNAME\_$USER/$time\_Documentbackup/$time\.txt

else

  echo "文件已存在"

fi

find -E / -iregex "$a" ! -path "/mnt/*" ! -path "/System/*" ! -path "/Applications/*" ! -path "/private/*" -print0 | xargs -0 -I F CP "F"  /ESAudit/$HOSTNAME\_$USER/$time\_Documentbackup

find -E / -iregex "$a" ! -path "/mnt/*" ! -path "/System/*" ! -path "/Applications/*" ! -path "/private/*"  >> /ESAudit/$HOSTNAME\_$USER/$time\_Documentbackup/$time\.txt



if [[ `cat /ESAudit/$HOSTNAME\_$USER/$time\_Documentbackup/$time\.txt |wc -l` -eq 0 ]];then

  rm -rf  /ESAudit/$HOSTNAME\_$USER/$time\.txt

fi







Audit2Office_SCP


#!/bin/bash



expect -c "

  spawn scp -r /ESAudit/$HOSTNAME\_$USER/$time root@192.168.2.54:/mnt/newmount/Office

  expect {

    \"*assword\" {set timeout 30; send \"password\r\";}

    \"yes/no\" {send \"yes\r\"; exp_continue;}

  }      

  expect eof"

       

rm -rf /ESAudit





Audit2Office_SCP


#!/bin/bash



expect -c "

  spawn scp -r /ESAudit/$HOSTNAME\_$USER/$time root@192.168.2.54:/mnt/newmount/Office

  expect {

    \"*assword\" {set timeout 30; send \"password\r\";}

    \"yes/no\" {send \"yes\r\"; exp_continue;}

  }      

  expect eof"

       

rm -rf /ESAudit





change_mac_address


#!/bin/bash

#



#网卡名称

EnX=$(/usr/bin/osascript -e 'display dialog "请输入网卡名称" default answer "" with icon note buttons {"OK"} default button "OK"

    set result1 to result

    set the text_data to text returned of the result

    set the button_data to button returned of the result1

    if button_data = "Cancel" then

      return ""

    end if

    return text_data')  

   

sudo ifconfig $EnX ether A4:BB:6D:E6:AE:FA  

networksetup -detectnewhardware

sudo ifconfig $EnX up  

sleep 3s



sudo ifconfig $EnX ether A4:BB:6D:E6:AE:FA  

networksetup -detectnewhardware

sudo ifconfig $EnX up  

sleep 3s



sudo ifconfig $EnX ether A4:BB:6D:E6:AE:FA  

networksetup -detectnewhardware

sudo ifconfig $EnX up  



(/usr/bin/osascript -e  'display dialog "修改成功!"  buttons {"OK"} default button "OK" ')

 














普通分类: