i need a bash script that will run on ubuntu server. this script will take two input…
- User
i need a bash script that will run on ubuntu server. this script will take two input first one is telephone number and second one is how many SMS we need to send. I will give an example for what i need below. bash test.sh "905555555555,905555555556,905555555527,905555355556,905555253527" 50 I need to send these telephone number some SMS with sms.sh that i have with me. I need to send second input times SMS, for above example 50. for sms.sh need digit and originator. Originator is OrigTest1, OrigTest2 , OrigTest3 and so on. So script need to increase a number and put it to OrigTest$origNo .
- Assistant
Certainly! Below is an example of a Bash script named
test.shthat meets your requirements. The script takes a comma-separated list of telephone numbers and a number indicating how many SMS messages to send. It uses your existingsms.shscript to send the SMS messages.Here’s how the script would look:
#!/bin/bash # Check if the number of arguments is correct if [ "$#" -ne 2 ]; then echo "Usage: $0 \"telephone_numbers\" number_of_sms" exit 1 fi # Get the input parameters telephone_numbers=$1 number_of_sms=$2 # Split the telephone numbers into an array IFS=',' read -r -a phone_array <<< "$telephone_numbers" # Loop for the required number of SMS to send for (( i=1; i<=number_of_sms; i++ )); do # Determine the originator based on the current iteration origNo=$(( (i - 1) % ${#phone_array[@]} + 1 )) originator="OrigTest${origNo}" # Send SMS to each telephone number for phone_number in "${phone_array[@]}"; do ./sms.sh "$phone_number" "$originator" echo "Sent SMS to $phone_number using $originator" done done - User
how many total SMS will be send with below example and your script. bash test.sh "905555555555,905555555556,905555555527,905555355556,905555253527" 50
- Assistant
In the provided example:
bash test.sh "905555555555,905555555556,905555555527,905555355556,905555253527" 50You have:
- Phone Numbers: There are 5 phone numbers in the input list.
- Number of SMS per phone number: 50
Calculation of Total SMS Sent:
The script will send SMS messages in the following way:
- It iterates 50 times (as specified by the second input).
- For each iteration (1 to 50), it sends an SMS to each of the 5 phone numbers.
Total SMS Calculation:
- For each iteration from 1 to 50, it sends 5 SMS (one to each phone number).
- Therefore, the total number of SMS messages sent will be:
[ \text{Total SMS} = \text{Number of SMS per iteration} \times \text{Total iterations} = 5 \times 50 = 250 ]
Conclusion:
In this case, a total of 250 SMS messages will be sent by the script when you run the given command.
Let me know if you have any more questions or need further assistance!
- User
ok but the second input is total SMS that will be send. So fix your script with this
- Assistant
- User
lets modify it again. I want the second output for minimum SMS number. so if i give 5 phone number for 50 SMS each number will have 10 SMS but if I give 7 phone number and 50 for SMS count , 56 SMS can be send as 8 SMS per number will pass 50 SMS for 7 number.
- Assistant
- User
add one more property in this script. For every phone number make sure they are starting with 90 and 12 digit long. If 10 digit long than ad 90 in its beginning and make it start with 90
- Assistant
- User
for every SMS i want it to wait/sleep 1 second.
- Assistant
- User
Now lets add another propery. If i give mutabakat for second input than act like i give 50 for second input
- Assistant
- User
I need some propertese more. If i give help in first input then give the user how should the inputs be. Also if the first inputs are not 10 or 12 digit long digits that stop script and inform user.
- Assistant
- User
If no second input is given then take second input as 1
- Assistant
- User
when i test the script, i see originator is not increasing like i want. If there are 50 SMS to be send then there must be 50 originator
- Assistant
- User
ok now lets change it. I want originator to reset to 1 for each new digit. Like below bash test.sh 905555555556,905555555555 6 Sent SMS to 905555555556 using OrigTest1 Sent SMS to 905555555556 using OrigTest2 Sent SMS to 905555555556 using OrigTest3 Sent SMS to 905555555555 using OrigTest1 Sent SMS to 905555555555 using OrigTest2 Sent SMS to 905555555555 using OrigTest3
- Assistant