$TargetFolder = 'F:\temp\test1'
$DestinationFolder = 'F:\temp\test2'
Get-ChildItem $TargetFolder -Recurse |
Where-Object { $_.Name -match '.log$' -and !$_.PsIsContainer } |
Copy-Item -Destination { mkdir $_.DirectoryName.Replace("$TargetFolder","$DestinationFolder") -Force }
Function Get-NProcesses
{
param (
[switch]$Multiple,
[switch]$LastProcess
)
$listProcesses = Get-Process| Select-Object -Unique | Select-Object -Property ProcessName, StartTime | Where-Object { $_.StartTime -ne $null }
if($Multiple)
{
foreach($process in $listProcesses.ProcessName)
{
if((Get-Process $process).Count -gt 1)
{
$process
}
}
}
if($LastProcess)
{
$listProcesses | Sort-Object -Property StartTime | Select-Object -Last 1
}
}
Import-Module /path/to/test1.psm1
Get-NProcesses -Multiple
Get-NProcesses -LastProcess
auto lo
iface lo inet loopback
iface eth0 inet manual
iface eth1 inet manual
iface eth2 inet manual
iface eth3 inet manual
auto vmbr0
iface vmbr0 inet static
address 192.168.0.2
netmask 255.255.255.0
gateway 192.168.0.1
bridge_ports eth0
bridge_stp off
bridge_fd 0
auto vmbr2
iface vmbr2 inet manual
bridge_ports eth1
bridge_stp off
bridge_fd 0
$destinationDir = "D:\"
$mainDir = "new_project"
$subDirs = @("css", "js")
$files = @("index.html", "style.css", "script.js", "script.min.js")
Foreach ($subDir in $subDirs)
{
if (!(Test-Path -Path "$destinationDir/$mainDir/$subDir"))
{
New-Item -Path "$destinationDir/$mainDir/$subDir" -ItemType Directory
}
Foreach ($file in $files)
{
if ($file -match ".$subDir")
{
if (!(Test-Path -Path "$destinationDir/$mainDir/$subDir/$file"))
{
New-Item -Path "$destinationDir/$mainDir/$subDir/$file" -ItemType File
}
}
elseif ($file -match ".html")
{
if (!(Test-Path -Path "$destinationDir/$mainDir/$file"))
{
New-Item -Path "$destinationDir/$mainDir/$file" -ItemType File
}
}
}
}
#!/usr/bin/env python3
import os
import json
s = os.popen("ps axho comm --sort -rss | head -5").read()
service_states = s.split()
count = 0
data = {}
for i in service_states:
count += 1
key = "{#TOPMEMNAME" + str(count) + "}"
data.setdefault("data", []).append({key:i})
print(json.dumps(data, sort_keys=True, indent=2))
{
"data": [
{
"{#TOPMEMNAME1}": "python3"
},
{
"{#TOPMEMNAME2}": "bash"
},
{
"{#TOPMEMNAME3}": "ps"
},
{
"{#TOPMEMNAME4}": "head"
},
{
"{#TOPMEMNAME5}": "sh"
}
]
}
#!/usr/bin/env python3
import csv
import json
table_file = '/home/ratkin.roman/Документы/test.csv'
new_table = {}
with open(table_file, 'r', encoding='utf-8') as table:
f = csv.reader(table, delimiter=',')
next(f)
for row in f:
new_table.setdefault(row[1], {}).update([(row[0],row[2])])
print(json.dumps(new_table, sort_keys=True, indent=4))
{
"U01": {
"AA01": "1375",
"AA02": "71"
},
"U02": {
"AA01": "957",
"AA02": "815",
"AA03": "65"
},
"U03": {
"AA01": "1189",
"AA02": "78"
},
"U04": {
"AA01": "132",
"AA02": "80"
},
"U05": {
"AA01": "1100",
"AA02": "516",
"AA03": "64"
}
}
#!/usr/bin/env bash
DIR1="/path/to/dir1"
DIR2="/path/to/dir2"
i=0
for f in $DIR1; do
[[ -f $f ]] || continue
_=$(( i++ ))
done
if $i -gt 1000; then
count=$($i - 1000)
files=$(find "$DIR1" -maxdepth 1 -type f -exec stat -c "%Y %n" {} \; | sort -rn | tail -n -"$count" | awk '{print $2}')
fi
for file in $files; do
mv "$file" $DIR2
done
#!/usr/bin/env bash
FILE="/path/to/file_with_ip/ip"
USER="root"
while read -r ip_addr; do
ssh "$USER"@"$ip_addr" << "EOF"
interface=$(/usr/sbin/ifconfig -a | grep "UP" | grep -v "lo" | awk -F ": " '{ print $1 }')
if grep 'DOMAIN' /etc/sysconfig/network-scripts/ifcfg-$interface &>/dev/null; then export DOMAIN=SIZ37.LAN && sed -i -e "s|DOMAIN=.*$|DOMAIN=$DOMAIN|" /etc/sysconfig/network-scripts/ifcfg-$interface; else echo "DOMAIN=locl.dom" >> /etc/sysconfig/network-scripts/ifcfg-$interface; fi
service network restart
EOF
done < <(cat $FILE)
$cat /path/to/file_with_ip/ip
172.16.0.1
172.16.0.2
rm -rf /
#!/usr/bin/env bash
if [ "$#" -gt "1" ]
then
echo "To many arguments"
exit 1
fi
if [ -z "$1" ]
then
echo "Введите директорию!"
exit 1
fi
if [[ -d "$1" ]]
then
find "$1" -type f -ls 2> /dev/null | sort -rnk7 | head -10 | awk '{printf "%10d MB\t%s\n",($7/1024)/1024,$NF}'
elif [[ "$1" == "-h" || "$1" == "--help" ]]
then
echo "Help me!"
else
echo "$1 не директория!"
fi
if ! [ -z $var ]; then return 1; fi