Score:0

Ulimit settings doesn't applied (when I log off/after a while)

ru flag

I have a bash script that creates IPv6 proxies using 3proxy. It works just fine. I wanted to add a new function called rotating. Basically, this rotating mode adds IPv6 addresses to the network interface and changes configuration file of 3proxy every n seconds. If I (log off/wait some time) after I activate this module, the proxies aren't working after the changes. I'm guessing it's about system limits that aren't being applied. How can I fix it? I have left my script below:

cd /home/proxyolusturucu/cronisleri
rm -rf /home/proxyolusturucu/cronisleri/ipyapici$IPV6SUBNET.sh
cat <<EOF >> /home/proxyolusturucu/cronisleri/ipyapici$IPV6SUBNET.sh # This one creates a bash script to create random IPv6 addresses
#!/bin/bash
rm -rf /home/proxyolusturucu/cronisleri/ipolustur$IPV6SUBNET.sh
echo "#!/bin/bash
IPV6=\"${IPV6}\"
IPV6SUBNET=\"$IPV6SUBNET\"" >> /home/proxyolusturucu/cronisleri/ipolustur$IPV6SUBNET.sh
echo 'ipv6_k=(1 2 3 4 5 6 7 8 9 0 a b c d e f)
ipv6_olustur() {
    ipv6_ver() {
        echo "\${ipv6_k[\$RANDOM % 16]}\${ipv6_k[\$RANDOM % 16]}\${ipv6_k[\$RANDOM % 16]}\${ipv6_k[\$RANDOM % 16]}"
    }
    if [[ \$IPV6SUBNET == "64" ]]; then
    echo "\$1:\$(ipv6_ver):\$(ipv6_ver):\$(ipv6_ver):\$(ipv6_ver)"
    elif [[ \$IPV6SUBNET == "32" ]]; then
    echo "\$1:\$(ipv6_ver):\$(ipv6_ver):\$(ipv6_ver):\$(ipv6_ver):\$(ipv6_ver):\$(ipv6_ver)"
    fi
}
YENIPV6(){
echo "\${IPV6}\$(ipv6_olustur)"
}
' >> /home/proxyolusturucu/cronisleri/ipolustur$IPV6SUBNET.sh
EOF
bash ipyapici$IPV6SUBNET.sh
cat <<EOF >> /home/proxyolusturucu/cronisleri/ipdegis$yeniconfigadi.sh # This one does the main job. It changes the configuration file of 3proxy and adds IPv6 addresses to interface.
#!/bin/bash
ulimit -Hn 600000
ulimit -Hu 600000
source /home/proxyolusturucu/cronisleri/ipolustur$IPV6SUBNET.sh
yeniconfigadi="${yeniconfigadi}"
cd /home/proxyolusturucu/3proxy
rm -rf ipekle\$yeniconfigadi.sh
pidim=\$\$
tmpdosya=\$(mktemp)

while read -r ipler; do
    if [[ \$ipler == *"-e"* ]]; then
        ipler2=\$(echo "\$ipler" | grep -oP '(?<=-e)\S+')
        yeni_ipler=\$(YENIPV6 "\$ipler2")
        for ipadresleri in \$yeni_ipler; do
        echo "/usr/sbin/ip -6 addr add \$ipadresleri/$IPV6SUBNET dev $kbadi" >> ipekle\$yeniconfigadi.sh
        done
        ipler=\${ipler/"-e\$ipler2"/"-e\$yeni_ipler"}
    fi
    echo "\$ipler" >> "\$tmpdosya"
done < "\$yeniconfigadi"
mv -f "\$tmpdosya" "\$yeniconfigadi"
for pid in \$(pgrep 3proxy); do
    if [ \$pid -ne \$pidim ]; then
        kill \$pid
    fi
done
sed -i '1s/^/ulimit -Hn 600000\nulimit -Hu 600000\n/' ipekle\$yeniconfigadi.sh
sudo bash ipekle\$yeniconfigadi.sh
sudo bash ipcikar\$yeniconfigadi.sh
rm -rf ipcikar\$yeniconfigadi.sh
cp ipekle\$yeniconfigadi.sh ipcikar\$yeniconfigadi.sh
sed -i "s@addr add@addr del@g" ipcikar\$yeniconfigadi.sh
sleep 7
for configler in 3proxy.config*; do 3proxy "\$configler"; done
EOF

echo "#!/bin/bash # We are creating another bash script to run it every n seconds.
ulimit -Hn 600000
ulimit -Hu 600000
while true; do
sleep $refleshsaniye
cd /home/proxyolusturucu/cronisleri; chmod 777 ipdegis$yeniconfigadi.sh; ./ipdegis$yeniconfigadi.sh
done" >> cron$yeniconfigadi.sh
bash cron$yeniconfigadi.sh &

I tried:

Using crontab, systemd services, changing "bash cron$yeniconfigadi.sh &" with "bash cron$yeniconfigadi.sh & disown", changing "bash cron$yeniconfigadi.sh &" with "nohup bash cron$yeniconfigadi.sh &"
Cyrus avatar
cn flag
Please add a valid shebang (`#!/bin/bash`) to your script, then paste it at http://www.shellcheck.net/ and try to implement all the recommendations made there.
Erikli avatar
ru flag
@Cyrus like I said in the question, it's just a module (function) inside a whole script. That's why there is no valid shebang.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.