script interview questions
Top script frequently asked interview questions
I have a set of repositories sorted into directories based on their VCS (Git, Mercurial, SVN). With Subversion I was able to run svn update *
in the parent directory and it would loop through each directory and update each repository as expected. That's not the case for Git or Mercurial.
I would like to come up with a bash script that I can run to do exactly that, loop through directories and either git pull
or hg pull
in each. I just don't have much bash scripting experience.
Source: (StackOverflow)
I have some bash scripts I have setup that mostly use
#!/bin/bash
but I regularly come across some that look like
#!/bin/bash -e
#!/bin/bash -x
#!/bin/bash -ex
and so on.
Can someone explain the meaning and benefits of these shebang options and whether they apply to other shebangs?
Source: (StackOverflow)
I need to frequently change the DNS server address, and for now I do it by opening 'network and sharing center' - 'local area connection' - properties - ipv4 - and then type the DNS numbers.
Is there a faster way to do it? Can I do it with a batch file or a powershell script? Is there a built in console command to change DNS?
Source: (StackOverflow)
How can I automatically run a script when I log on to Windows?
I'd like to run something like this whenever I log into my computer:
echo %USERNAME% logged on at %DATE% %TIME% >> log.txt
A bonus would be to be able to run the same script whenever I unlock the screen saver as well.
Source: (StackOverflow)
How to make a script execute as root, no matter who executes it?
I read about setuid but I'm not sure how to do this.
I'm using Linux, Ubuntu 12.04 LTS.
Source: (StackOverflow)
I have a bunch of hand-rolled executable scripts in my $HOME/bin directory. Some are written in bash, some in Ruby. All of them have the shebang line at the top telling the shell what interpreter to use (bash or Ruby, in my case).
I'm wondering if it is better to put file extensions on these scripts to indicate what scripting language they are written in? For example, the scripts in Ruby would have the *.rb suffix, and the bash ones would have the *.sh suffix.
Currently, these scripts just have simple names with no file extension.
What's the best practice?
Source: (StackOverflow)
I need to run a (Tcl, or whatever) script on a remote Unix machine, from a (local) Windows command shell, and I want the stdout/stderr of the script to show up in the Windows CLI. The exit code would also be useful.
Is this possible using ssh (putty)? Or by any other means?
Thanks!
Source: (StackOverflow)
I want to remove all files from a folder structure, so I'm left with an empty folder structure.
Can this be achieved in either batch or VBScript scripting?
I have tried a very basic batch command, but this required the user to allow the deletion of each file. This wasn't a suitable solution as there are many hundreds of files and this will increase massively over time.
What can you suggest?
Source: (StackOverflow)
I'm looking for a way to reboot machines after getting an email notification.
The setup I want to use this on is a render farm. We have 5 boxes with 8 Nvidia GTX 980Ti in them. They're running Windows 10 Professional 64-bit.
The issue we are having is that they sometimes freeze or "stall" while rendering. I have it set up so once this happens I receive an email saying "x machine has stalled."
I have automated everything on the machines; they log in automatically, open up the necessary programs, initiate a connection with our license server, and map all the required network drives.
Basically all you have to do is turn it off and back on, and it works again.
So what I'm wondering is, can I set up a program, event, or a script that will tell the machines to reboot after I receive the email saying a machine has stalled?
The machine that will be running this is running Windows 7 Pro 64-bit.
Source: (StackOverflow)
Could someone tell me how to disable ipv6 auto-config on a specific network interface in CentOS?
The current situation is:
A PC has two network adapters eth0 and eth1 that are connecting to the same LAN, in which, IPv6 router is advertising an IPv6 prefix with NDRA (Neighbor Discovery Router Advertisements) packet. As a result, both eth0 and eth1 are configuring the IPv6 address with that prefix automatically.
But, I just want to enable ipv6 on eth1 and disable it on eth0. I've tried the following methods, but they don't work.
1. /etc/sysconfig/network
NETWORKING_IPV6=no
IPV6_AUTOCONF=no
This will disable ipv6 on both eth0 and eth1.
2. /etc/sysconfig/network-scripts/ifcfg-eth0
IPV6INIT=no
IPV6_AUTOCONF=no
Then, it doesn't work. I have restarted the network service already. I am a little confused about this issue. Thanks in advanced.
Source: (StackOverflow)
I have an interactive shell script, that at one place needs to ssh to another machine (Ubuntu based) and execute something as root (the user should enter his password, but the remote command should run like noted in the script):
# ...
ssh remote-machine 'sudo ls'
# ...
However, I always get this error message back:
sudo: no tty present and no askpass program specified
OK, that's quite clear. But how can I circumvent this? Something like this should happen:
$ ssh remote-machine 'sudo ls /'
[sudo] password for user1:
/bin
/etc
/var
Source: (StackOverflow)
We are doing all our scripting with Bash so far, but I'm starting to feel a bit silly about it. While we can of course do everything we want with Bash (it's quite powerful), I'm starting to wonder if we shouldn't use a proper scripting language (in our case most likely Ruby) instead.
How do you decide when to use Perl/Python/Ruby over Bash for a script? I don't think an init script with Ruby makes sense, but how about a slightly longer script that adds email accounts?
Source: (StackOverflow)