Support Support Downloads Knowledge Base Service Request Manager My Juniper Community

Knowledge Base

Search our Knowledge Base sites to find answers to your questions.

Ask All Knowledge Base Sites All Knowledge Base Sites JunosE Defect (KA)Knowledge BaseSecurity AdvisoriesTechnical BulletinsTechnotes Sign in to display secure content and recently viewed articles

How to run an Unix shell command in Junos CLI or run a CLI command in shell

0

0

Article ID: KB31557 KB Last Updated: 26 Mar 2020Version: 2.0
Summary:

The Junos Command Line Interface (CLI) has many operation commands to replace shell commands. However in some cases, a user might want to execute a Unix shell command under CLI without actually leaving the CLI, and vice versa. This article provides examples on how to do that.

Solution:

Example of running a shell command in CLI operational mode:

user@router> start shell command "ls -al /var/tmp"
total 52
drwxrwxrwt   8 root  field   512 Feb 21 15:27 .
drwxr-xr-x  33 root  wheel  1024 Jul 14  2010 ..
drwxr-xr-x   2 root  field   512 Jan  1  2010 gres-tp
drwxrwxrwx   2 root  wheel   512 Jul 14  2010 install
-rw-r--r--   1 root  field    46 Jul 14  2010 kmdchk.log
-r--r--r--   1 root  field   237 Feb 21 13:44 preinstall_boot_loader.conf
drwxrwxrwt   2 root  wheel   512 Jan  1  2010 vi.recover


You can specify which shell (csh or sh) as shown in the example below:

user@router> start shell ?                              
Possible completions:
  <[Enter]>            Execute this command
  csh                  Start C shell
  sh                   Start Bourne-style shell (really ash)
  user                 Start shell as another user
  |                    Pipe through a command
 
user@router> start shell csh command "ls -al /var/tmp"
total 52
drwxrwxrwt   8 root  field   512 Feb 21 15:27 .
drwxr-xr-x  33 root  wheel  1024 Jul 14  2010 ..
drwxr-xr-x   2 root  field   512 Jan  1  2010 gres-tp
drwxrwxrwx   2 root  wheel   512 Jul 14  2010 install
-rw-r--r--   1 root  field    46 Jul 14  2010 kmdchk.log
-r--r--r--   1 root  field   237 Feb 21 13:44 preinstall_boot_loader.conf
drwxrwxrwt   2 root  wheel   512 Jan  1  2010 vi.recover


Note: The argument 'command' is hidden by default and introduced in 14.1.

Samples of running CLI command under Junos shell

% cli show system uptime
Current time: 2017-03-29 07:53:32 IST
Time Source:  NTP CLOCK
System booted: 2017-02-21 13:53:02 IST (5w0d 18:00 ago)
Protocols started: 2017-02-21 13:55:47 IST (5w0d 17:57 ago)
Last configured: 2017-02-28 10:44:40 IST (4w0d 21:08 ago) by labroot
 7:53AM  up 35 days, 18:01, 2 users, load averages: 0.04, 0.08, 0.08


To implement a CLI command with pipe through: “|”

% cli show system uptime \| no-more
Current time: 2017-03-29 07:57:34 IST
Time Source:  NTP CLOCK
System booted: 2017-02-21 13:53:02 IST (5w0d 18:04 ago)
Protocols started: 2017-02-21 13:55:47 IST (5w0d 18:01 ago)
Last configured: 2017-02-28 10:44:40 IST (4w0d 21:12 ago) by labroot
 7:57AM  up 35 days, 18:05, 2 users, load averages: 0.12, 0.07, 0.07
Modification History:
2020-03-23: Article reviewed for accuracy; no changes required.
Comment on this article > Affected Products Browse the Knowledge Base for more articles related to these product categories. Select a category to begin.

Security Alerts and Vulnerabilities

Security Alerts and Vulnerabilities Product Alerts and Software Release Notices Problem Report (PR) Search Tool EOL Notices and Bulletins JTAC User Guide Customer Care User Guide Pathfinder SRX High Availability Configurator SRX VPN Configurator Training Courses and Videos End User Licence Agreement Global Search