Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands & Shells

Generating and Running Multiple Scripts

Submitted by on January 9, 2019 – 4:45 pm

Admittedly, this has a limited range of practical applications and is more of a scripting exercise. The command shown here generates a bunch of temporary scripts each containing the sleep command for up to one minute.

The scripts are ran in the background and upon exit will delete themselves. The number of processes will be limited to one-tenth on the maximum number of processes allowed by the kernel on your server.

(( x = $(grep -m1 [0-9] /proc/sys/kernel/pid_max) / 10 ))
for i in $(seq 1 ${x}); do
f=$(mktemp); chmod 700 ${f}
cat << EOF > ${f}
#!/bin/bash
sleep $(expr $RANDOM % 61)
rm -- "\
(( x = $(grep -m1 [0-9] /proc/sys/kernel/pid_max) / 10 ))
for i in $(seq 1 ${x}); do
f=$(mktemp); chmod 700 ${f}
cat << EOF > ${f}
#!/bin/bash
sleep $(expr $RANDOM % 61)
rm -- "\$0"
EOF
( ${f} & ); done
" EOF ( ${f} & ); done

 

Print Friendly, PDF & Email

Leave a Reply