Induced gravitational waves in a general cosmological background