How to send at command in linux

How to send AT commands to a modem in Linux?

it seems to work. I type an AT and get an OK . I type some crap, I get an ERROR . It seems that modem1 for minicom is somehow configured to use the modem at /dev/ttyACM0 . How can I use socat to send AT commands? Do I need to configure something? Maybe I can use configurations for modem1 of minicom (I do not know how to find/see this configuration)?

Additional information

Is the given socat command correct? Should I play with some options? With the -v option I see the following:

AT > 2013/10/23 17:10:28.917413 length=3 from=0 to=2 AT < 2013/10/23 17:10:28.921598 length=3 from=0 to=2 AT AT ksjdhfjdgfhjkdfh >2013/10/23 17:10:30.244923 length=17 from=3 to=19 ksjdhfjdgfhjkdfh < 2013/10/23 17:10:30.251383 length=29 from=3 to=31 ksjdhfjdgfhjk\b \bd\b \bf\b \bh\b \b ksjdhfjdgfhj 
[5983726.808063] usb 2-1: USB disconnect, device number 3 [5983730.800021] usb 2-1: new full-speed USB device number 4 using uhci_hcd [5983730.920014] usb 2-1: device descriptor read/64, error -71 [5983733.629524] usb 2-1: New USB device found, idVendor=0572, idProduct=1329 [5983733.629533] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [5983733.629539] usb 2-1: Product: USB Modem [5983733.629544] usb 2-1: Manufacturer: Conexant [5983733.629549] usb 2-1: SerialNumber: 24680246 [5983733.632673] cdc_acm 2-1:1.0: ttyACM0: USB ACM device 
speed 57600 baud; line = 0; eof = ^A; min = 1; time = 0; -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -echo -echoe 

Источник

How to Use ‘at’ Command to Schedule a Task on Given or Later Time in Linux

As an alternative to cron job scheduler, the at command allows you to schedule a command to run once at a given time without editing a configuration file.

The only requirement consists of installing this utility and starting and enabling its execution:

# yum install at [on CentOS based systems] $ sudo apt-get install at [on Debian and derivatives]

Next, start and enable the at service at the boot time.

--------- On SystemD --------- # systemctl start atd # systemctl enable atd --------- On SysVinit --------- # service atd start # chkconfig --level 35 atd on

Once atd is running, you can schedule any command or task as follows. We want to send 4 ping probes to www.google.com when the next minute starts (i.e. if it’s 22:20:13, the command will be executed at 22:21:00) and report the result through an email ( -m , requires Postfix or equivalent) to the user invoking the command:

# echo "ping -c 4 www.google.com" | at -m now + 1 minute

If you choose to not use the -m option, the command will be executed but nothing will be printed to standard output. You can, however, choose to redirect the output to a file instead.

Читайте также:  See all users and groups in linux

In addition, please note that at not only allows the following fixed times: now, noon (12:00), and midnight (00:00), but also custom 2-digit (representing hours) and 4-digit times (hours and minutes).

To run updatedb at 11 pm today (or tomorrow if the current date is greater than 11 pm), do:

To shutdown the system at 23:55 today (same criteria as in the previous example applies):

# echo "shutdown -h now" | at -m 23:55

You can also delay the execution by minutes, hours, days, weeks, months, or years using the + sign and the desired time specification as in the first example.

Time specifications are subject to the POSIX standard.

Summary

As a rule of thumb, use at instead of cron job scheduler whenever you want to run a command or execute a given task at a well-defined time only once. For other scenarios, use cron.

Next, we shall cover how to encrypt tar archive files using openssl, till then stay connected to Tecmint.

Gabriel Cánepa is a GNU/Linux sysadmin and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Delete Huge Files in Linux

Parted Command in Linux

TLDR Man Pages for Linux Commands

apt-get Command Examples

Ubuntu apt-cache Commands

apt Command Examples

5 thoughts on “How to Use ‘at’ Command to Schedule a Task on Given or Later Time in Linux”

Good article, Gabriel! Just my 5 cents to it. “at” can be used to start something on background, like nohup staff, but more short:
$ echo “rsync remote_resource local_resource” | at now
or
$ at -f /path/to/my/script -m now
just notice “-f script” option – it’s very convenient to run more complex staff “at” can be used instead of cron to run something repeatedly after the first execution ends. This can eliminate cronjobs, scheduled to run each minute with various locks to avoid to run several commands simultaneously. One can add at the end of its script:
—— bash code snippet —–
# script payload here
this_script_name=$(basename $0)
this_script_path=$(readlink –canonicalize $(dirname $0))
at -f $this_script_path/$this_script_name now
—— bash code snippet —–
this will start the script again when it’s finished. Another interesting application that’s unable to implement with cron is periodically execution with random intervals. Mostly the same as abouve, but just add random delay:
—— bash code snippet —–
# script payload here
this_script_name=$(basename $0)
this_script_path=$(readlink –canonicalize $(dirname $0))
MIN_DELAY=15
RANDOM_BIAS=20
delay=$(( ($RANDOM % $RANDOM_BIAS) + $MIN_DELAY ))
at -f $this_script_path/$this_script_name now + $delay min
—— bash code snippet —– That’s all 🙂 Reply

Читайте также:  Изменить размер экрана linux

Источник

Linux at Command: A Convenient Tool for Scheduled Jobs

As a Linux system administrator, we always look for ways to automate repetitive tasks and save time. Linux provides you with the at command for scheduling one-time jobs to run at a specified time.

In this article, we’ll explore the at command and how to use it to streamline your system administration tasks.

The content of this article includes:

Linux at Command

The at command in Linux is a powerful tool for scheduling tasks to execute them at a certain defined time. It allows users to specify the exact date and time when a command should be run. The at command allows users to manage different tasks automatically.

The at command also includes the

The “atq” is used to display pending tasks for a specific user, while root users can view all tasks. The output format shows the task ID, date, hour, queue, and username.

On the other hand, “atrm” is used to delete tasks using their job number.

These commands provide additional functionality and control for managing scheduled tasks with the at command in Linux.

Installing at Command in Linux

The Linux at command might not be by default installed in your system. To install at on Linux, use the below-given command:

Understanding the at command

The at command is used to schedule jobs to run at a specific time in the future, without the need for a continuous process running in the background. The command works by adding jobs to a queue, which are then executed at the designated time.

The syntax of the at command is as follows:

  • f filename: Specifies a file containing the commands to run
  • m: Sends email notification when the job is completed
  • q queue: Specifies the job queue to use
  • v: Verbose output
  • time: The time at which to run the job

You can schedule jobs using a variety of time formats, including absolute times, relative times, and times specified as minutes past the hour.

Absolute time expressions include:

  • YYMMDDhhmm[s]: This format specifies the abbreviated year, month day, hour, minutes and also seconds option.
  • CCYYMMDDhhmm[s]: This format includes the complete year, month day, hour, minutes and seconds.
  • now: This specifies the current time or immediate execution of at command.
  • midnight: This equals to 00:00 AM.
  • noon: This equals to 12:00 PM.
  • teatime: This time is taken as 4 PM.
  • AM: Time before noon or 12:00 PM.
  • PM: Time after noon or 12:00 PM.
  • today: This specifies the current day.
  • tomorrow: This specifies the day after today.
Читайте также:  Qemu kvm astra linux

For example, the given below command will print “Hello” at 4PM:

To specify a relative time expression using at command, we have to specify the command by adding the “+” plus sign in any one of these:

For example, to schedule a task at 5 minutes after current time, use:

Schedule a Bash Script Using at Command

Using the at command is straightforward. Simply enter the command followed by the time at which you want the job to run and the command you want to execute.

For example, to run a script, follow the below-given syntax:

Note: I have created a bash script that will append the text “Hello World” inside a file “myfile.txt” whenever it’s executed.

We can verify the content inside the file using the cat command to ensure the script is run successfully at the given time.

Interactively Scheduling a Job Using at Command

Using the at command in Linux, users can interactively schedule tasks by specifying the desired execution time and entering the corresponding commands at the prompt. This process is like creating events in a calendaring app.

For example, we can create a memo text and schedule it like a remainder on a specific time. Run the following command to schedule a memo that adds “Linuxhint” in a text file at specified time:

After executing the above command, add the following command to add a text “Linuxhint” inside a file.

To exit the at prompt, users can press CTRL+D on their keyboard.

Note: The above command creates a text file and appends the text inside the file.

After the task has run, one can verify its execution by using the cat command on the corresponding file.

Scheduling a Job with at

The at command in Linux allows users to schedule tasks by piping commands to it using echo without using the interactive prompt.

For example, users can specify the delay time in minutes and the “now” notation to schedule a task, as shown in the following example:

This command schedules a task to run 1 minute from the current time and appends the text “Welcome to Linuxhint” inside the file when executed.

Using this method, we can schedule tasks without the need for interactive input.

After one minute, run the cat command to verify the schedule execution:

List all Running Jobs

To list all running jobs, you can run:

Источник

Оцените статью
Adblock
detector