# # Restrict script to console use
APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Restrict script to console use

I've removed advertising from most of this site and will eventually clean up the few pages where it remains.

While not terribly expensive to maintain, this does cost me something. If I don't get enough donations to cover that expense, I will be shutting the site down in early 2020.

If you found something useful today, please consider a small donation.



Some material is very old and may be incorrect today

© November 2013 Anthony Lawrence

A customer asked for a way to prevent a certain shell script from execution by SSH - it apparently it is supposed to be run only at the console.

One choice is to examine 'tty'. Something like this, perhaps:



#!/bin/bash case `tty` in /dev/tty*) echo "ok";; /dev/pts/*) echo "No";exit 0; esac echo "Will proceed"

Or perhaps one of the SSH variables can be tested:



#!/bin/bash test -n $SSH_CLIENT && exit 1 echo "Will proceed"

However, that $SSH_CLIENT will not be set if you "su -" to another user after logging in with ssh, so you may need to use the more direct test.


If you found something useful today, please consider a small donation.



Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

->
-> Restrict script to console use


Inexpensive and informative Apple related e-books:

Take Control of iCloud

iOS 10: A Take Control Crash Course

Photos for Mac: A Take Control Crash Course

Take Control of Automating Your Mac

Digital Sharing Crash Course





More Articles by © Anthony Lawrence





Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us


Printer Friendly Version





UNIX is simple. It just takes a genius to understand its simplicity. (Dennis Ritchie)




Linux posts

Troubleshooting posts


This post tagged:

Linux

Scripting

Shell

Unix



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode